simple soccer gam 376 robin burke fall 2006. outline game implementation project #1

30
Simple Soccer GAM 376 Robin Burke Fall 2006

Upload: may-hill

Post on 12-Jan-2016

218 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

Simple Soccer

GAM 376

Robin Burke

Fall 2006

Page 2: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

Outline

Game Implementation Project #1

Page 3: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

Admin

Homework #3 due today

Grading I am behind but no other homework due for awhile

Upcoming 10/9: Design phase of Soccer project 10/11: Midterm 10/17: Soccer project

Page 4: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

Simple Soccer

A 2D sports game 5 agents per team

4 field players1 goal keeper

1 ball 1 field 2 goals

Page 5: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

Architecture

Main loopUpdate SoccerPitchRedraw

SoccerPitchresponsible for updating what is on

the field

Page 6: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

SoccerPitch

Walls on all four sidesno throw-ins or goal kicks

Regions18 rectangular regionsfor positioning players

Goalseach tracks number of goals scored

Page 7: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

MovingEntity

Abstract class for all moving objectshas steering behaviors

SubclassesSoccerBallFieldPlayer

Page 8: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

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?

xavv f 22

Page 9: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

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

Page 10: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

Simple Soccer

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"

Page 11: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

Team state

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

Page 12: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

Offense

Defense Kickoff

other team possession

our team possession

goal scored

goal scored

play starts

Page 13: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

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

Page 14: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

Support Spot

Considers 30 positions on the opponent's half of the field

Calculates which position canreceive a pass andcan shoot a goal andare close enough to ball

Supporting player will try to go to the best support spot

Page 15: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

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

Page 16: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

Steering behaviors

tracking the ball "visually" chasing the ball steering to support position goalie has special behavior to get in

blocking position

Page 17: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

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

Page 18: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

ChaseBall

KickBall

ReturnToHR

closest

in range

not closest

at home

Wait

in receiving range

Dribble

can't kick

goal or pass attempt

can't shoot or pass

kicked

MSG: Receive_Ball

ReceiveBallSupportAttacker

MSG: Go_Home

MSG: Support

Page 19: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

Goal Keeper

Different states TendGoal

interpose self between ball and goal midpoint

InterceptBallif within tending range

PutBallBackIntoPlaypasses to nearest player

Page 20: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

Key Calculations

Is a pass safe? predict trajectory of ball predict closest intercept of each opponent

Is it possible to shoot? test positions along the goal mouth does this randomly

Who to pass to? tests all of the teammates for validity and nearness to

goal Where to place the pass?

out of opponents range within receivers range

Page 21: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

Demo

Page 22: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

SteeringSoccerLab

Not the same as Buckland's Allows multiple team implementations Records the CPU time used by each

AI implementation Don't use Buckland's code

Page 23: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

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

Page 24: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

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

Page 25: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

AbstractFactory

Page 26: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

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)

Page 27: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

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

Page 28: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

Project #1

Two parts Design (10/6)

tell me what you want to do to create a better team

Implementation (5 pm, 10/17) deliver implementation I will compile and check compatibility

Tournament (10/18) In class Last minute changes OK

Page 29: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

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

Page 30: Simple Soccer GAM 376 Robin Burke Fall 2006. Outline Game Implementation Project #1

Monday

Lab using SimpleSoccer