Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Projet IA04 - Vivarium
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Zhenyang Xu
Projet IA04 - Vivarium
Commits
e22e9bef
Commit
e22e9bef
authored
1 year ago
by
noere
Browse files
Options
Downloads
Patches
Plain Diff
exemple fonction combat
parent
95aa72de
Branches
main
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
agents/animaux.go
+35
-0
35 additions, 0 deletions
agents/animaux.go
with
35 additions
and
0 deletions
agents/animaux.go
+
35
−
0
View file @
e22e9bef
package
agents
// fonction combat
import
(
"fmt"
"math/rand"
"time"
)
type
Animal
struct
{
Energie
float64
Hiérarchie
float64
Âge
float64
}
func
combat
(
animal1
,
animal2
Animal
)
string
{
rand
.
Seed
(
time
.
Now
()
.
UnixNano
())
score1
:=
0.5
*
animal1
.
Energie
+
0.5
*
animal1
.
Hiérarchie
+
0.5
*
animal1
.
Âge
+
0.5
*
rand
.
Float64
()
score2
:=
0.5
*
animal2
.
Energie
+
0.5
*
animal2
.
Hiérarchie
+
0.5
*
animal2
.
Âge
+
0.5
*
rand
.
Float64
()
if
score1
>
score2
{
return
"Le premier animal a gagné le combat!"
}
else
if
score2
>
score1
{
return
"Le deuxième animal a gagné le combat!"
}
return
"Le combat s'est terminé par une égalité!"
}
func
main
()
{
animal1
:=
Animal
{
Energie
:
100
,
Hiérarchie
:
3
,
Âge
:
5
}
animal2
:=
Animal
{
Energie
:
90
,
Hiérarchie
:
2
,
Âge
:
3
}
result
:=
combat
(
animal1
,
animal2
)
fmt
.
Println
(
result
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment