Project 2
Mini team sports game simulation
(50 points)
Due: 12/09 Monday 11:59 pm
No late submission accepted
Computer Gaming Simulation
Computer gaming is a computer simulation of a
virtual world
Game designers must have knowledge of the
following to make people, objects, and
environments behave realistically in a virtual world:
– Computer graphics
– Artificial intelligence
– Human-computer interactions and simulation
– Software engineering
– Computer security
– Fundamentals of mathematics
– Laws of physics relating to gravity, elasticity, light, and sound
2
3
https://www.youtube.com/wat
ch?v=I6AjwpwxhoQ
Creating the Virtual World
Game engine–a software system within which
games can be created
Following functionality provided by tools of a game
engine:
• A rendering engine for graphics
• A physics engine to provide a collision detection system
and dynamics simulation
• A sound-generating component
4
Creating the Virtual World
Additional functionality resulting from tools of a game
engine:
• A scripting language apart from the code driving the
game
• Animation
• Artificial intelligence algorithms (e.g., path-finding
algorithms)
• A scene graph that holds the spatial representation
in a graphical sense
5
Soft Skills
High Quality Game Design and Development
Requires Effective Use of “Soft Skills”:
• Effective collaboration with designers, programmers, and
artists on various technical ideas throughout the entire
game design and development process
• Flexibility and adaptability as the game design constantly
evolves and changes throughout the development and
production process
6
Soft Skills
• Willingness to abandon much of the completed design
work when the game’s story line, mechanics, art,
programming, audio, video, and/or scripting requires
significant changes
7
Game Programming
A variety of application programming interfaces
(APIs) and libraries are available to help
developers with key programming tasks
The choice of API determines which vocabulary
and calling conventions the programmer should
employ to use the services
The target game platform determines which
service the programmer will use; some libraries
permit efficient cross-platform development
8
Game Programming
Coding process begins with the creation of “the
game loop”
Game loop is responsible for managing the game
world, regardless of any input from the user
For example, the game loop might update enemy
movement in the game or check for victory/loss
conditions
Basically, the game loop manages the simulation
9
10
What Is Simulation?
Simulation
A model of a complex system and the experimental
manipulation of the model to observe the results
Systems that are best suited to being simulated are
dynamic, interactive, and complicated
Model
An abstraction of a real system
It is a representation of the objects within the system
and the rules that govern the interactions of the objects
11
Constructing Models
Continuous simulation
– Treats time as continuous
– Expresses changes in terms of a set of differential equations
that reflect the relationships among the set of characteristics
– Meteorological models fall into this category
12
Thinking Machines
Can you
list the items
in this
picture?
https://www.youtube.com/watch?v=QdQL11uWWcI
http://www.theverge.com/2013/9/17/4740466/how-siri-found-its-voice-video
13
Thinking Machines
Can you
list the items
in this
picture?
Can you count the
distribution of letters in a book?
Add a thousand4-digit numbers?
Match finger prints?
Search a list of a million values
for duplicates?
Humans do best Computers do best
14
Thinking Machines
Artificial intelligence (AI)
The study of computer systems that attempt to model and
apply the intelligence of the human mind
For example, writing a program to pick out objects in a
picture
15
The Turing Test
Turing test
A test to empirically determine
whether a computer has achieved
intelligence
Alan Turing
An English mathematician who wrote
a landmark paper in 1950 that asked
the question: Can machines think?
He proposed a test to answer the
question “How will we know when
we’ve succeeded?”
16
The Turing Test
https://deepmind.com/alpha-go.html
17
The Turing Test
Weak equivalence
Two systems (human and computer) are equivalent in
results (output), but they do not arrive at those results in the
same way
Strong equivalence
Two systems (human and computer) use the same internal
processes to produce results
18
Robotics
Mobile robotics
The study of robots that move relative to their environment,
while exhibiting a degree of autonomy
Sense-plan-act (SPA) paradigm
The world of the robot is represented in a complex
semantic net in which the sensors on the robot are used to
capture the data to build up the net
19
Subsumption Architecture
Rather than trying to model the entire world all the time, the
robot is given a simple set of behaviors each associated with
the part of the world necessary for that behavior
20
Subsumption Architecture
Recursive Searching:
Simple maze!
21
4 4 4 4 4 4 4
4 0 0 0 0 0 4
4 0 4 0 4 0 4
4 0 0 4 0 4 4
4 0 4 0 0 0 4
4 0 0 0 4 0 4
4 4 4 4 4 4 4
4 4 4 4 4 4 4
4 7 7 7 7 7 4
4 7 4 7 4 7 4
4 7 7 4 0 4 4
4 7 4 7 7 7 4
4 7 7 7 4 7 4
4 4 4 4 4 4 4
4 4 4 4 4 4 4
4 7 7 7 7 7 4
4 7 4 7 4 7 4
4 7 7 4 0 4 4
4 7 4 7 7 7 4
4 7 7 7 4 7 4
4 4 4 4 4 4 4
Project 2
Mini team sports game simulation
(50 points)
Due: 12/09 Monday 11:59 pm
No late submission accepted
• Soccer Rules: The basic rules of soccer for kids and adults.
• https://www.youtube.com/watch?v=M18UNJDspO4
• Football Simulator
• http://www.betstatz.com/simulator
http://www.agame.com/games/soccer
http://www.y8.com/games/the_champions_4_-
_world_domination
http://www.y8.com/tags/soccer
http://www.ea.com/uk/news/national-team-infographics http://www.eloratings.net/system.html
http://www.sportsnet.ca/hockey/nhl/easports-nhl-14-predicts-boston-bruins-stanleycup-san-jose-sharks/
http://www.easports.com/2014-fifaworld-cup/news/2014/ea-sports-2014-
fifa-world-cup-prediction
http://keithlyons.me/
blog/2014/05/30/pred
icting-the-outcome-ofthe-2014-fifa-worldcup/
Unified Modeling Language (UML)
• The UML is a visual modeling language that enables system
builders to create blueprints that capture their visions in a
standard, easy-to-understand way, and provides a
mechanism to effectively share and communicate these
visions with others.
The key is to organize the design process in a way that analysts, clients,
programmers, and others involved in system development can understand and
agree on.
The UML provides the organization.
Project Requirement
1. UML Diagram document
WashingMachine class is a template for creating
new instances of washing machines.
WashingMachine |
brandName modelName serialNumber capacity |
acceptClothes() acceptDetergent() turnOn() turnOff() |
Attributes
brandName
modelName
serialNumber
capacity
Operations
acceptClothes()
acceptDetergent()
turnOn()
turnOff()
Class Diagram
Object Diagram
myWasher:WashingMachine :WashingMachine
Working with Object- Orientation
Visualizing a Class
• a rectangle is the icon that represents a class
• If your class has a two- word name, join the
two words together and capitalize the first
letter of the second word (as in
WashingMachine )
• the UML represents a package as a tabbed
folder.
• If the WashingMachine class is part of a
package called Household, you can give it
the name Household::WashingMachine. The
double colons separate the package name
on the left from the classname on the right.
This type of classname is called a pathname
WashingMachine
Household |
Household::WashingMachine
Attributes
• An attribute is a property of a class. It
describes a range of values that the property
may hold in objects (that is, in instances) of
that class. A class may have zero or more
attributes.
• By convention, a one-word attribute name
is written in lower- case letters. If the name
consists of more than one word, the words
are joined and each word other than the first
word begins with an uppercase letter. The
list of attribute names begins below a line
separating them from the class name.
• Every object of the class has a specific value
for every attribute. Note that an object’s
name begins with a lowercase letter, precedes a colon that precedes the class name,
and the whole name is underlined.
WashingMachine |
brandName modelName serialNumber capacity |
myWasher: WashingMachine |
brandName = “Laundatorium” modelName = “Washmeister” serialNumber = “GL57774” capacity = 16 |
An object has a specific value
for every one of its class’s
attributes.
An attribute can show its type
as well as a default value.
• The UML gives you the option of indicating additional
information for attributes. In the icon for the class, you can
specify a type for each attribute’s value. Possible types include
string, floating-point number, integer, and Boolean (and other
enu- merated types). To indicate a type, use a colon to separate
the attribute name from the type. You can also indicate a
default value for an attribute. a
WashingMachine |
brandName: String = “Laundatorium” modelName: String serialNumber: String capacity: Integer |
Operations
• An operation is something a class can do,
and hence it is something that you (or
another class) can ask the class to do.
• The list of operations begins below a line
that separates the operations from the
attributes
• In the parentheses that follow an operation
name, you can show the parameter that the
operation works on, along with that
parameter’s type. One kind of operation, the
function, returns a value after it finishes
doing its work. For a function, you can show
the value it returns and that value’s type.
• These pieces of information about an
operation are called the operation’s signature. The first two operations show the type
of the parameter. The third and fourth show
the type of the return value.
WashingMachine |
brandName modelName serialNumber capacity |
acceptClothes() acceptDetergent() turnOn() turnOff() |
WashingMachine |
brandName modelName serialNumber capacity |
acceptClothes(c:String) acceptDetergent(d:Integer) turnOn():Boolean turnOff():Boolean |
Attributes, Operations,
and Visualization
• In practice, you don’t always show all
of a class’s attributes and operations
• An ellipsis indicates that the
displayed attributes or operations
aren’t the whole set.
• You can use a keyword to organize a
list of attributes or operations.
WashingMachine |
WashingMachine |
brandName … |
acceptClothes() … |
WashingMachine |
«id info» brandName modelName serialNumber «machine info» capacity |
«clothes-related» acceptClothes() acceptDetergent() «machine-related» turnOn() turnOff() |
Responsibilities and Constraints
• In a class icon, you can write the class’s
responsibilities in an area below the
operations list area.
WashingMachine |
brandName modelName serialNumber capacity |
acceptClothes() acceptDetergent() turnOn() turnOff() |
Take dirty clothes as input and produce clean clothes as output. |
WashingMachine |
brandName modelName serialNumber capacity |
acceptClothes() acceptDetergent() turnOn() turnOff() |
capacity = 16 or 18 or 20 lb
• The rule in curly brackets
constrains the capacity attribute to
be one of three possible values.
Classes—What
They Do and How to
Find Them
• An initial class
diagram for
modeling the game
of basketball.
Analyst: “Coach, what’s basketball all about?”
Coach: “The goal of the game is to shoot the ball through the basket and score more
points than your opponent. Each team consists of five players: two guards, two
forwards, and a center. Each team advances the ball toward the basket with the
objective of ultimately shooting the ball through the basket.”
Analyst: “How does it advance the ball?”
Coach: “By dribbling and passing. But the team has to take a shot at the basket
before the shot clock expires.”
Analyst: “Shot clock?”
Coach: “Yes. That’s 24 seconds in the pros, 30 seconds in international play, and 35
seconds in college to take a shot after a team gets possession of the ball.”
Analyst: “How does the scoring work?”
Coach: “Each basket counts two points, unless the shot is from behind the threepoint line. In that case, it’s three points. A free throw counts one point. A free throw,
by the way, is the penalty a team pays for committing a foul. If a player fouls an
opponent, play stops and the opponent gets to shoot at the basket from the free-throw
line.”
Analyst: “Tell me a little more about what each player does.”
Coach: “The guards generally do most of the dribbling and passing. They’re typically shorter than the forwards, and the forwards are usually shorter than the center.
All the players are supposed to be able to dribble, pass, shoot, and rebound. The
forwards do most of the rebounding and intermediate-range shoot- ing, while the
center stays near the basket and shoots from close range.”
Analyst: “How about the dimensions of the court? And by the way, how long does a
game last?”
Coach: “In international play, the court is 28 meters long by 15 meters wide. The
basket is 10 feet off the ground. In the pros, a game lasts 48 minutes, divided into four
12-minute quarters. In college and international play, it’s 40 minutes divided into two
20-minute halves. A game clock keeps track of the time remaining.”
UML Project Diagram
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Slide 1- 37
• Your program must include
1. Class design
• Must have classes such as person, player, referee, game class etc.
2. Method/function blocks
• Design your own methods (e.g., scoring, penalty kick etc.)
3. User inputs, Loops & Conditional statements
• Being used to design your game logics
4. Arrays (including an array of objects) and Pointer variable (*)
• Must demonstrate how to use both primitive array data and an array of objects
5. Game logics (2 Semi-finals & Final game)
• 3 games.
6. Randomization for base scoring/performance
• Review previous assignment (also next slide)
7. Adding Penalty kick mechanism
• Computer vs. User choice. Make a game more fun and dynamic through a user
interaction.
8. File generation (summary result output to both screen and txt format)
• Generate a txt file to show the summary (winner, total score, MVP etc. Be creative)
• Display ranking in sorted order.
• Review lecture 5
50 points
Project requirement:
1. Your project is due by 12/01 11:59 pm. No late submission will be accepted.
2. This is an individual assignment, no plagiarism. If more than 20% of your code looks similar/same from
another person’s work, your work will be considered as ‘copying, violating plagiarism’, and both people (who
provides codes and you) will receive ‘0’ on this project.
3. This project will weigh 10% of your semester grade.
4. You must submit one zip file including all your Java files (test it before you submit!) and one MS Word
document (minimum 3 pages, name it as project_youLastnameFirstnameInitial.docx)
• In your MS Word document,
• Provides overall summary of your design approach
• summarize the highlights of your work including your unique design features
• indicates things/reason/constraints which you weren’t able to accomplish (even if some of your
program lacks required components, you may get some partial marks by explaining why/what went
wrong)
• UML diagram
5. Please review all the specification describe in next pages.
6. Some bonus mark will be added on your extra work.
Team and Player data generation
Generate 2 semi-final games and one final game,
a) For the final game, two winning teams from the semi-final game should battle for
the championship!
b) Using array(s) (1D or 2D), create minimum 4 teams, and define minimum 3
variables/factors characterizing team performance (i.e., Nationality reputation,
Speed, Power, Injury, Teamwork and Star Player)
• Game play interface: When two teams for each game are selected, you program must
display both name of each country(or team) and name of all 4 players with each player’s
(minimum) 3 skill levels.
• Also, when the game ends, the game statistics/results should both be displayed on
the monitor and be generated as ‘wcResult.txt’ file showing the summary (3 games:
score of each team from 2 semi-final games, and the final game) This topic (file
read/write) will be covered next week.
• Your program should display the record of all 4 teams, and output the team ranks in
order based on each member variable, not total. Also, calculate the total sum for each
team, and show the winning team. Also, try an extra factor (quality of star player)
1. Functions relate to game play Game mechanics/play
a) Scoring (goal!) can be achieved by comparing performance of team players from two different teams:
b) Design functions relate to attack and defense functions.
• Not all 4 players should get involved in attack or defense. Pick a random number of players who will
be involved in attack and defense. Then compare their total skill sets on top of overall team
reputation/performance. You must design your own formula to figure out combined skill sets of
multiple players. Also, consider how you can incorporate overall team reputation/performance into
player’s performance.
• Example: Aassign a random value (1 as poor -5 as best) to 3 variables (speed, power, and/or
teamwork) and 2 user entered values (Nationality and Star Player) relate to performance and apply
these values to performance formula you designed (e.g. Performance = 2 x Nationality + Speed x
Power + Teamwork + Star Player – injury) .
• Could However, the magnitude of selected weight variable is not known to the user (Surprise! Apply
random selected weight values for each team). If less than 1 (multiply this weight value to a selected
variable; recalculation!), under performance than previous initial sum. If more than 1 (multiplied by
weight >1), this special weight value introduced on one variable would perform better than the
normal weight (1.0).
a. Design functions relate to penalty function as well as a function representing a unique skill to
goalkeeper (e.g., catchingBall).
b. Design functions relate to foul, and receiving Yellow or Red card (Link explaining foul and
yellow/red card from referee : http://www.understandingsoccer.com/rule-12-fouls-andmisconduct.html ). Red card removes a player from the game.
1. Using array(s) (1D or 2D), create minimum 4 teams, and define 5 variables/factors( 3 random
values and 2 value entered by a user) characterizing team performance (i.e., Nationality
reputation, Speed, Power, Injury, Teamwork and Star Player)
2. To compare initial performance of each team, assign a random value (1 as poor -5 as best) to 3
variables (speed, power, and/or teamwork) and 2 user entered values (Nationality and Star
Player) relate to performance and apply these values to performance formula you designed (e.g.
Performance = 2 x Nationality + Speed x Power + Teamwork + Star Player – injury) .
3. Team competition is based on the total sum of all member variables for each team. To make the
game more engaging, apply one weight value directly to manipulate/change one specific
member variable entered by the user(either speed, power or teamwork) affecting initial sum.
4. However, the magnitude of selected weight variable is not known to the user (Surprise! Apply
random selected weight values for each team). If less than 1 (multiply this weight value to a
selected variable; recalculation!), under performance than previous initial sum. If more than 1
(multiplied by weight >1), this special weight value introduced on one variable would perform
better than the normal weight (1.0).
5. Your program should display the record of all 4 teams, and output the team ranks in order based
on each member variable, not total. Also, calculate the total sum for each team, and show the
winning team. Also, try an extra factor (quality of star player)
Tips for Bonus mark! Add more factors affecting
game play and user interaction.
• Research what typically happens at the championship? Who can
be a MVP? Audience factor?
• Any extra factor affecting game condition? Different locations?
Weather? Home advantage?
• Feel free to add more detail/refinement on certain functions
(e.g., different attack types?)
International Hockey Results.txt
Penalty kick mechanism
56
Problem Solving
Problem solving
The act of finding a solution to a perplexing, distressing,
vexing, or unsettled question
How do you define problem solving?
57
Problem Solving
How to Solve It: A New Aspect of Mathematical Method by
George Polya
“How to solve it list” written within the context of
mathematical problems
But list is quite general
We can use it to solve computer
related problems!
58
Problem Solving
How do you solve problems?
Understand the problem
Devise a plan
Carry out the plan
Look back
59
Strategies
Ask questions!
– What do I know about the problem?
– What is the information that I have to process in order the find
the solution?
– What does the solution look like?
– What sort of special cases exist?
– How will I recognize that I have found
the solution?
60
Strategies
Ask questions! Never reinvent the wheel!
Similar problems come up again and again in different
guises
A good programmer recognizes a task or subtask that has
been solved before and plugs in the solution
Can you think of two similar problems?
61
Strategies
Divide and Conquer!
Break up a large problem into smaller units and solve each
smaller problem
– Applies the concept of abstraction
– The divide-and-conquer approach can be applied over and
over again until each subtask is manageable
62
Computer Problem-Solving
Analysis and Specification Phase
Analyze
Specification
Algorithm Development Phase
Develop algorithm
Test algorithm
Implementation Phase
Code algorithm
Test algorithm
Maintenance Phase
Use
Maintain
Can you
name
a recurring
theme?
63
Phase Interactions
Should we
add another
arrow?
(What happens
if the problem
is revised?)
64
Algorithms
Algorithm
A set of unambiguous instructions for solving a
problem or subproblem in a finite amount of time
using a finite amount of data
Abstract Step
An algorithmic step containing unspecified details
Concrete Step
An algorithm step in which all details are specified
Review
C++ class (Chapter 2)
Copyright © 2017, 2012, 2008 Pearson Education, Inc. All Rights Reserved
C++ Classes
C++ Supports the use of classes to define new data types.
• Definition of a new class type requires a
– Class Declaration
– Class Implementation
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Object-Oriented Programming
Object-oriented programming: focused on creating
objects
Object: entity that contains data and procedures
Data is known as data attributes and procedures are known as
methods
Methods perform operations on the data attributes
Encapsulation: combining data and code into a single
object
Unified Modeling Language (UML)
• The UML is a visual modeling language that enables system
builders to create blueprints that capture their visions in a
standard, easy-to-understand way, and provides a
mechanism to effectively share and communicate these
visions with others.
The key is to organize the design process in a way that analysts, clients,
programmers, and others involved in system development can understand and
agree on.
The UML provides the organization.
Washing Machine
http://www.bestbuy.ca/enCA/category/washers/33931p.aspx
http://www.bestbuy.ca/enCA/product/lg-electronics-lg-29-6-0-cuft-front-load-washer-wm9000hva-silverwm9000hva/10397331.aspx?path=d35ca
49232f245250683b52917cad954en02
WashingMachine class is a template for creating
new instances of washing machines.
WashingMachine |
brandName modelName serialNumber capacity |
acceptClothes() acceptDetergent() turnOn() turnOff() |
Attributes
brandName
modelName
serialNumber
capacity
Operations
acceptClothes()
acceptDetergent()
turnOn()
turnOff()
Class Diagram
Object Diagram
myWasher:WashingMachine :WashingMachine
Object Diagram
myWasher:WashingMachine
Samsung:WashingMachine Whirlpool:WashingMachine
LG:WashingMachine |
Superclass & subclass
Appliance |
Appliances inherit the attributes
and operations of the Appliance
class. Each one is a subclass of the
Appliance class. The Appliance class
is a superclass of each subclass.
Superclasses can also be subclasses and inherit from
other superclasses.
Appliance |
Copyright © 2017, 2012, 2008 Pearson Education, Inc. All Rights Reserved
To run chapter 2.3 example from Textbook source code
1. Create a new project by choosing File > New >
Project. Choose Empty project (or Console window).
2. Remove any existing file from the project
3. Press/hold RMB (right mouse button click), and
select Add to Project option.
4. Choose three files (chapter2_3.cpp, Point.cpp and
Point.h)
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Object-Oriented Programming (cont’d.)
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Object-Oriented Programming (cont’d.)
Data hiding: object’s data attributes are hidden from
code outside the object
Access restricted to the object’s methods
Protects from accidental corruption
Outside code does not need to know internal structure of the object
Object reusability: the same object can be used in
different programs
Example: 3D image object can be used for architecture and
game programming
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Object-Oriented Programming (cont’d.)
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Classes
Class: code that specifies the data attributes and
methods of a particular type of object
Similar to a blueprint of a house or a cookie cutter
Instance: an object created from a class
Similar to a specific house built according to the blueprint or a
specific cookie
There can be many instances of one class
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Classes (cont’d.)
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Classes (cont’d.)
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Classes (cont’d.)
Copyright © 2017, 2012, 2008 Pearson Education, Inc. All Rights Reserved
Class Declarations
• Typically written in a file named “className.h”.
• Begins with keyword class followed by the name (identifier)
of the new class type.
• Body of the class declaration is a block of code containing
– declaration of data members (attributes)
– method (function) prototypes
– keywords public, protected, and private are used to
control access to data members and methods
– A semicolon must terminate the body of the class
declaration. };
Copyright © 2017, 2012, 2008 Pearson Education, Inc. All Rights Reserved
Class Implementation
• The class is typically written in a file named
“className.cpp”
• File should
• Provides the code to implement class methods.
Copyright © 2017, 2012, 2008 Pearson Education, Inc. All Rights Reserved
Class Syntax
Copyright © 2017, 2012, 2008 Pearson Education, Inc. All Rights Reserved
Class Methods
• Define the operations that can be performed on class objects.
– A constructor is a special method that is executed when objects of t
class type are declared (instantiated).
– Constructors have the same name as the class.
– A class may define multiple constructors to allow greater flexibility in
creating objects.
▪ The default constructor has no parameters.
▪ Parameterized constructors provide initial values for data member
Copyright © 2017, 2012, 2008 Pearson Education, Inc. All Rights Reserved
Using a Class
• Once a class is defined, you may use the class name as a
type specifier.
– You must include the class declaration (i.e. header file)
– You must link to the class implementation (i.e. .cpp file)