1 / 42

Simple Soccer

Simple Soccer. GAM 376 Robin Burke Winter 2008. Outline. Game Implementation Project #1. Admin. Homework #3 due today Grading I am behind but no other homework due for awhile Upcoming 1/31: Design phase of Soccer project 1/29: Midterm 2/12: Soccer project. Simple Soccer.

boone
Download Presentation

Simple Soccer

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Simple Soccer GAM 376 Robin Burke Winter 2008

  2. Outline • Game Implementation • Project #1

  3. Admin • Homework #3 • due today • Grading • I am behind • but no other homework due for awhile • Upcoming • 1/31: Design phase of Soccer project • 1/29: Midterm • 2/12: Soccer project

  4. Simple Soccer • A 2D sports game • 5 agents per team • 4 field players • 1 goal keeper • 1 ball • 1 field • 2 goals

  5. Issues for Sports AI • Perfection • player agents cannot be perfect • unrealistic, unbeatable • Roles • in team sports, players usually have well-defined roles • Stats • player performance is usually governed by stats • abstract quantities standing in for physical abilities • categories: defense, speed, etc. • interactions between players calculated based on stat comparisons and random factors

  6. Architecture • Main loop • Update SoccerPitch • Redraw • SoccerPitch • responsible for updating what is on the field

  7. SoccerPitch • Walls on all four sides • no throw-ins or goal kicks • Regions • 18 rectangular regions • for positioning players • Goals • each tracks number of goals scored

  8. MovingEntity • Abstract class for all moving objects • has steering behaviors • Subclasses • SoccerBall • FieldPlayer

  9. SoccerBall • embeds some of the physics of its motion • FuturePosition • Δx = v Δt + ½ afΔt2 • where af is the deceleration due to friction • TimeToCoverDistance • Δt = (v' – v) / af • but what is v' • issues • what if inner part is negative? • then the ball won't get that far • what is the initial velocity, v?

  10. Velocity Reset • What really happens? • a player swings a foot • moment of interaction with ball • impulse • new velocity results • really it is a foot/ball collision • But not necessary to model it this way • assume that the ball is stopped before a kick • players can't add to existing velocity • OK, because it looks OK • much easier to model • Initial velocity • equals impulse acceleration • equals F / m • So we can calculate TimeToCoverDistance • given two points and a force

  11. Soccer Players • Implementation of a 5-player soccer team • Two state machines • "Team state" • "Player state" • Tiered state machines • common in tactical FPS games • teams have a tactical state • "flanking" • and each member has its own role • "covering fire"

  12. Team states • kickoff • everybody go to default position • not true soccer kickoff • offense • look for opportunities to get a pass upfield from the player with the ball • defense • go to defensive position • closest player chases ball

  13. Offense other team possession goal scored our team possession Kickoff Defense goal scored play starts

  14. Problems?

  15. Team Behaviors • Tracks passes • receiving player of a pass • set when a pass is made • Tracks ball • closest player to the ball • constantly updated • Controlling player • the player with the ball • Supporting player • a player that will get into position for a pass

  16. Support Spot • Considers 30 positions on the opponent's half of the field • Calculates which position can • receive a pass and • can shoot a goal and • are close enough to ball • Supporting player will try to go to the best support spot

  17. Player state • defense • chase ball if you're the closest • offense • move toward goal with ball • pass if possible • without ball (if supporting player) • move to support spot • ask for pass • otherwise • do nothing

  18. Steering behaviors • tracking the ball "visually" • chasing the ball • steering to support position • goalie has special behavior to get in blocking position

  19. State Machine • Global state • routes messages • Wait • ReceiveBall • accept a pass • KickBall • make a pass • Dribble • try to move the ball downfield • ChaseBall • try to take possession of the ball • ReturnToHomeRegion • go home for kickoff • SupportAttacker • go to supporting position

  20. MSG: Support MSG: Receive_Ball SupportAttacker ReceiveBall MSG: Go_Home not closest in receiving range ChaseBall Dribble kicked ReturnToHR in range can't shoot or pass can't kick KickBall closest at home Wait goal or pass attempt

  21. Goal Keeper • Different states • TendGoal • interpose self between ball and goal midpoint • InterceptBall • if within tending range • PutBallBackIntoPlay • passes to nearest player

  22. Issues for Player AI • Passing • when is it effective to pass? • when is it safe to pass? • Shooting • when is it possible to shoot? • where to aim a shot?

  23. Passing B U A

  24. Tests • Create target positions • player himself • to points on a circle around the player • Ignore • opponents behind passer • opponents farther away than the target • Calculate • time for ball to arrive at intercept position • test whether opponent can reach the position before the ball • Prefer targets closer to the goal • also considers target position near target player

  25. Shooting U

  26. Test • Examine a few random locations across the goal mouth • treat like pass targets • can opponents intercept?

  27. Demo • What don’t the players do?

  28. SoccerLab • Not the same as Buckland's • Allows multiple team implementations • Records the CPU time used by each AI implementation • Do not use Buckland's code

  29. Abstract class • AbstSoccerTeam • all soccer teams must subclass • Abstract functions • CreatePlayers • teams can have different player setups • InitStateMachine • for team state machine • teams can have different team FSMs • InitPlayers • Name

  30. How to allow different opponents? • Need students to make their own soccer teams • need to run tournament in which teams compete • don't want to recompile when adding a team • How to make extensible code that doesn't need recompilation? • In particular • how can I create an instance if I don't know the name of the class

  31. Factory pattern • Basic idea • have a class whose job it is to create other objects • Get around the need to compile a call to new • a call to new requires a class name at compile time • A factory class • calls new • but we can use polymorphism • we can have a bunch of different factories • Result • what gets created is a function of which factory we choose • a decision that can be made at run time

  32. AbstractFactory

  33. Registration • How to know which factory object to use? • Static instance that registers a name on instantiation • Table associating factories with names • Result • dynamic object creation • (A bit easier in Java using reflection)

  34. Implementation • TeamMaker class • includes a static "registry" member • table of name, class pairs • has a newTeam method • looks up the factory class in the table • calls its makeTeam method • The class stored here is a subclass of TeamMaker • must implement makeTeam • makes an instance of the right team object • must include a static member with an instance of itself • when that instance is created • it calls the TeamMaker constructor with a name • the factory class is then registered under that name

  35. Abstract Code • SoccerTeamFactory.h class SoccerTeamFactory {public: MakeSoccerTeam(std::stringteam_id, Goal* home_goal,Goal* opponents_goal, SoccerPitch* pitch, team_colorcolor); }; • TeamMaker.h class TeamMaker { public: static AbstSoccerTeam* newTeam(string name, Goal* home_goal, Goal* opponents_goal, SoccerPitch* pitch, AbstSoccerTeam::team_colorcolor); } TeamMaker::TeamMaker (std::string className) { if (registry == NULL) registry = new MakerMap(); registry->insert( std::make_pair(className, this) ); }

  36. Team Code • SoccerTeamMaker const SoccerTeamMakerSoccerTeamMaker::registerThis; SoccerTeamMaker::SoccerTeamMaker() : TeamMaker("BucklandTeam") {} SoccerTeam* SoccerTeamMaker::makeTeam(Goal* home_goal, Goal* opponents_goal, SoccerPitch* pitch, SoccerTeam::team_colorcolor) const { return new SoccerTeam(home_goal, opponents_goal, pitch, color); }

  37. Project #1 • Two parts • Design (1/31) • tell me what you want to do to create a better team • Implementation (5 pm, 2/11) • deliver implementation • I will compile and check compatibility • Tournament (2/12) • In class • Last minute changes OK

  38. Teams • Team A • Allen / Irsheid • Team B • Bandes / Wit • Team C • Beasley / O'Brien • Team D • Dalbke /Lopardo • Team E • Gittens / Loane • Team F • Horst /Kuhlenschmidt • Team G • Koharcheck / Kruse • Team H • Perez

  39. Tournament rules • Round-robin • 1 game matches • 5 minutes / match • Scoring • Lower scoring team • get a bonus if they used less CPU time • 20% less CPU = 1 point • Ties go to the most efficient team • Degenerate strategies disqualified • Randomized elements must stay

  40. Getting Started • Download my SoccerLab code • Requires (but does not include) • Buckland’s Common directory • Read the Simple Soccer chapter • consider possible improvements that Buckland suggests

  41. Demo • Where is the stupidity? • Possible fixes

  42. Thursday • Begin discussion of graphs / pathfinding • Tuesday • Lab using SimpleSoccer

More Related