Soccer

Soccer preview image

1 collaborator

Avatar_black Leo B (Author)

Tags

competition 

Tagged by Leo B over 10 years ago

soccer 

Tagged by Leo B over 10 years ago

soccer, competition, sport 

Tagged by Leo B over 10 years ago

sports 

Tagged by Leo B over 10 years ago

Visible to everyone | Changeable by the author
Model was written in NetLogo 5.0.5 • Viewed 959 times • Downloaded 77 times • Run 0 times
Download the 'Soccer' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

;; TODO : 
;; une partie seulement va chercher la balle 

breed[players player]
breed[balls ball]

players-own[
  team
  HaveBall?
  GoalNumber
  target
  KeepingBall
  TakingBall
  Speed
  ]

globals[
  width
  height
  GoalColor
  PointTeam1
  PointTeam2
]

balls-own[
 owner 
 SpeedBall
]

patches-own[
 available? 
]

to SETUP
  ;; (for this model to work with NetLogo's new plotting features,
  ;; __clear-all-and-reset-ticks should be replaced with clear-all at
  ;; the beginning of your setup procedure and reset-ticks at the end
  ;; of the procedure.)
  __clear-all-and-reset-ticks
  set width 25
  set height 18
  set GoalColor green - 2
  set PointTeam1 0
  set PointTeam2 0
  prepare-patch
  prepare-turtle
end 

to GO
  every Speed-Simulation[
  Catch-ball
  PlayWithBall
  BallMove
  PutGoal
  TacticalMove
  Move
  GiveBall
  ]
end 

to PlayWithBall
  ask players[
    if(HaveBall?)[
    let Goal nobody
    if(team = "left")[
      set Goal patches with [pxcor > 0]
    ]
    if(team = "right")[
      set Goal patches with [pxcor < 0]
      ]
    set Goal Goal with [pcolor = GoalColor]
    set Goal min-one-of Goal [distance myself]
    set target Goal
    ]
  ]
end 

to TacticalMove
  ask players[

    let BallOwner [owner] of one-of balls
    
    if((BallOwner != nobody) and (not HaveBall?) and ([team] of BallOwner = team))[
        let patchTarget nobody
        if([team] of BallOwner  = "left")[
          set patchTarget one-of patches with [pxcor > 0]
        ]
        if([team] of BallOwner = "right")[
          set patchTarget one-of patches with [pxcor < 0]
        ]
        set target patchTarget
      ]
      if((BallOwner != nobody) and (not HaveBall?) and ([team] of BallOwner != team))[
        set target one-of balls
      ]
    ]
end 

to GiveBall
  ask players[
   if (HaveBall?)[
     let friend players with [team = [team] of myself]
     set friend friend with [distance myself > 5]
     if (team = "left")[
       set friend friend with [xcor >= [xcor] of myself]
     ]
     if (team = "right")[
       set friend friend with [xcor <= [xcor] of myself]
     ]
     set friend max-one-of friend [distance myself]
     if (friend != nobody)[
     set HaveBall? false
     ask balls[
       set owner friend
       set SpeedBall 0.8
     ]
     ]
   ] 
  ]
end 

to Move
  ask players[
    if target != nobody [
      face target
    ]

    let BallOwner [owner] of one-of balls
    let AllPlayers players
if(BallOwner != nobody)  [
  ask BallOwner[
    set AllPlayers other players
  ]
]

    if ([available?] of patch-ahead 1 and count other AllPlayers in-cone 2 90 = 0)[
     ifelse(HaveBall?)[set Speed 0.5][set Speed 0.7]
     right random 60
     left random 60
     fd Speed 
   ]
  ]
end 

to PutGoal
  let Goal? false
  ask players[
   if(HaveBall?)[
let seegoal patch-ahead 1
if ([pcolor] of seegoal = GoalColor)[
  ask balls [die]
  if (team = "left") [ set PointTeam1 PointTeam1 + 1]
  if (team = "right") [ set PointTeam2 PointTeam2 + 1]
  set GoalNumber GoalNumber + 1
  set HaveBall? false
  set Goal? true
   ]
   ]
  ]
  if (Goal?) [
    print "new game"
    create-ball 0 0
    ask players[
      set target one-of balls
    ]]
end 

to BallMove
  ask balls [
   if(owner != nobody)[
     face owner
     fd SpeedBall
     ifelse (distance owner >= 1) [set color violet + 1][set color black]
   ] 
  ]
end 

to Catch-ball
  ask players[
    if (not HaveBall?) [
  let prey one-of balls with [distance myself < 1]
  if prey != nobody[
    let take random TakingBall
    if (([owner] of prey = nobody) OR (([owner] of prey != nobody) AND (take > [KeepingBall] of [owner] of prey) ))[
    ask prey [ 
      if owner != nobody [ ask owner[ set HaveBall? false]]
      set owner myself 
      set SpeedBall 0.5]
    set HaveBall? true
    set Speed 0.5
    ]
    ]
    ]
  ]
end 

to prepare-patch
  ask patches[
    set pcolor green
    set available? true
  ]
  let land GetLand
  ask land [
    set pcolor white
        set available? false
  ]
  let goal GetGoal
  ask goal
  [
    set pcolor GoalColor
        set available? false
    ]
end 

to prepare-turtle
create-ball 0 0
create-teams red blue
end 

to-report GetLand
  report patches with [(pxcor = width OR pxcor = -1 * width OR pycor = height OR pycor = -1 * height) AND pxcor <= width AND pxcor >= -1 * width AND pycor <= height AND pycor >= -1 * height]
end 

to-report GetGoal
  report patches with [((pxcor <= -1 * width AND pxcor >= -1 * width - 2)or(pxcor >= width AND pxcor <= width + 2)) and (pycor >= -3 and pycor <= 3)]
end 

to create-ball [x y]
  create-balls 1[
     set xcor x
     set ycor y 
     set color black
     set shape "ball football"
     set owner nobody
     set SpeedBall 0.5
  ]
end 

to create-teams [color-team1 color-team2]
  create-players 11[
    set xcor -1 * random (width - 1)
    set ycor (2 * random (height - 1)) - (height - 2)
   set color color-team1
   set team "left"
  ]
  create-players 11[
    set xcor random (width - 1)
    set ycor (2 * random (height - 1)) - (height - 2)
    set color color-team2
    set team "right"
  ]
  ask players [
     set shape "person" 
     set HaveBall? false
     set GoalNumber 0
     set KeepingBall random 100
     set TakingBall random 100
     set Speed 0.4
     set target one-of balls
  ]
end 

There is only one version of this model, created over 10 years ago by Leo B.

Attached files

File Type Description Last updated
Soccer.png preview Preview for 'Soccer' over 10 years ago, by Leo B Download

This model does not have any ancestors.

This model does not have any descendants.