17-Othello
date post
07-Sep-2014Category
Documents
view
109download
0
Embed Size (px)
Transcript of 17-Othello
A Game of Othello Othello: popular board game (often known as Reversi) 8x8 board, black and white tokens Today, we will use it as a design example
CS 150 Spring 2008 Lec #22: Othello Design Example - 1
Othello: Rules and Game Play The object of the game is to have the majority of your colour discs on the board at the end of the game Rules
Black places two black discs and White places two white discs as shown in here. The game always begins with this setup. A move consists of "outflanking" your opponent's disc(s), then flipping the outflanked disc(s) to your colour. To outflank means to place a disc on the board so that your opponent's row (or rows) of disc(s) is bordered at each end by a disc of your colour. (A "row" may be made up of one or more discs). Here's one example: White disc A was already in place on the board. The placement of white disc B outflanks the row of three black discs.
CS 150 Spring 2008 Lec #22: Othello Design Example - 2
Outflanking ExampleWhite disc A was already in place on the board. The placement of white disc B outflanks the row of three black discs.
White flips the outflanked discs and now the row looks like this:
CS 150 Spring 2008 Lec #22: Othello Design Example - 3
Rules Black always moves first. If on your turn you cannot outflank and flip at least one opposing disc, your turn is forfeited and your opponent moves again. However, if a move is available to you, you may not forfeit your turn. A disc may outflank any number of discs in one or more rows in any number of directions at the same time - horizontally, vertically or diagonally. You may not skip over your own color disc to outflank an opposing disc.
CS 150 Spring 2008 Lec #22: Othello Design Example - 4
Rules Discs may only be outflanked as a direct result of a move and must fall in the direct line of the disc placed down.
All discs outflanked in any one move must be flipped, even if it is to the player's advantage not to flip them at all. Once a disc is placed on a square, it can never be moved to another square later in the game.CS 150 Spring 2008 Lec #22: Othello Design Example - 5
Rules When it is no longer possible for either player to move, the game is over. Discs are counted and the player with the majority of his or her colour discs on the board is the winner.
CS 150 Spring 2008 Lec #22: Othello Design Example - 6
Our Design Problem Design an Othello Board and Gamekeeper. The gamekeeper willKeep track of the score and state of the board Indicate whose move it is Indicate where legal moves can be made Accept and make a legal moveFlip all the discs who have been outflanked
Focus of todays lecture
Game engine and logic alone We will assume
Display device for an 8x8 board Input device which tells us where to move on an 8x8 board
CS 150 Spring 2008 Lec #22: Othello Design Example - 7
Global Picture of Our SystemCircuit in Each Square to: 1. Keep State of the Square 2. Compute whether move in square is legal
Game Controller
1.
Global Game State 2. Orchestrates individual move logic
CS 150 Spring 2008 Lec #22: Othello Design Example - 8
Game Controller State MachineFlip Current Color
NLegal Move?
Flip Current Color Legal Move?
Game Over
Current Color = White
N
YUpdate Board
Y Move selectedEnable Move
Move selected
CS 150 Spring 2008 Lec #22: Othello Design Example - 9
Square FSM Basic FunctionsStore state of square (Empty, White, Black) Report when move is legal Report when user moves into square Update state of square in response to a move
Current Color
Move Enabled
Square
Move Selected
Legal Move
CS 150 Spring 2008 Lec #22: Othello Design Example - 10
Square Finite State MachineState=none
k
t Se
te= b
lac
sta wh te=
Se t
sta
ite
Flip whiteState=black State=white
Flip black
Finite State Machine (Macro) per Othello Square
CS 150 Spring 2008 Lec #22: Othello Design Example - 11
Whats a Legal Move? Decided in each square Square state must be empty
Run of colorsStraight line of squares of one color bordered by a square of the other colorWhite run: line of white squares terminated by black square Black run: line of black squares terminated by white square Current run: line of squares of current color terminated by square of other color
Legal moveSquare is empty and neighbor square is part of current run
CS 150 Spring 2008 Lec #22: Othello Design Example - 12
Key Consideration for Cell Is it on a run in any direction?Originates a white (black) run:Cell is white (black); and Neighbor in direction is black (white); Cell is white (black); and Neighbor in direction continues or originates a white (black) run
Continues a white (black) run
Move to a square is legal if and only ifCurrent Mover is white (black) Current State is empty Some neighbor continues or orginates a black (white) run
CS 150 Spring 2008 Lec #22: Othello Design Example - 13
Originating and Continuing a Run
Begins a black run
Continues a white run
Begins a white run
CS 150 Spring 2008 Lec #22: Othello Design Example - 14
Legal Moves
Legal to move white Legal to move black How do we build a circuit to pick this up?
CS 150 Spring 2008 Lec #22: Othello Design Example - 15
Two Functions Per Color and direction RemoteBlack: this square is white all the squares in some direction are white until we hit a black Reverse black/white for Remote White
RemoteOrLocalBlack: this square is black OR remoteBlack is true for this square
Note that if a square is empty both remote and remoteOrLocal are false.
CS 150 Spring 2008 Lec #22: Othello Design Example - 16
Originating and Continuing a Run
remoteWhiteEast remoteOrLocalBlack (all directions) remoteOrLocalBlack East
remoteOrLocalWhite (all directions) remoteOrLocalBlackWest remoteBlackWest
remoteOrLocalWhite (all directions)remoteOrLocalBlackWest remoteBlackWest
CS 150 Spring 2008 Lec #22: Othello Design Example - 17
Cell circuit pictureNW Neighbor North Neighbor NE Neighbor
Local Inputs and Outputs (Connections to Adjoining cells) Cell has remote black Cell has remote white Cell has localOrRemote black Cell has localOrRemote white Flip black Flip white Global Outputs Cell color (black, white, none) Legal to move to current color
West Neighbor
Othello Cell
East Neighbor
SW Neighbor
South Neighbor
SE Neighbor
CS 150 Spring 2008 Lec #22: Othello Design Example - 18
RemoteBlack (Continue White Run)Cell Color = white SE Neighbor localOrRemote black Remote black to (NW neighbor)
Computation of remote (8x2, one to each neighbor x one per color)
White run to NW White run from SECS 150 Spring 2008 Lec #22: Othello Design Example - 19
RemoteOrLocal black (on white run or neighbor can start white run)Cell Color = black remoteBlack local orRemoteblack to (NW neighbor)
Computation of localOrRemote (8x2, one to each neighbor x one per color)
CS 150 Spring 2008 Lec #22: Othello Design Example - 20
Cell circuit pictureNW Neighbor North Neighbor NE Neighbor
On each link:2 wires in 4 wires outLocal Inputs and Outputs (Connections to Adjoining cells)Cell has remote black Cell has remote white Cell has localOrRemote black Cell has localOrRemote white Flip black Flip white
West Neighbor
Othello Cell
East Neighbor
Global OutputsSW Neighbor South Neighbor SE Neighbor Cell color (black, white, none) Legal to move to current color
CS 150 Spring 2008 Lec #22: Othello Design Example - 21
Legal Move Move to a square is legal if and only ifCurrent Mover is white (black) Current State is empty Some neighbor continues or orginates a black (white) run
Translate into our circuitCurrent Mover is white (black) Current State is empty For some direction: neighbors remoteWhite (black)
CS 150 Spring 2008 Lec #22: Othello Design Example - 22
Computation of LegalCurrent Mover = black NW remote black
Current Mover = white NW remote white 8 inputs, one per neighbor Cell color = none legal
Computation of legal
Computation from one direction
Replicate here from each neighbor
CS 150 Spring 2008 Lec #22: Othello Design Example - 23
Whats the delay? Worst case is on edge or cornerAt most 7 AND or OR gates on remote chain Computation of legal is ~6 gates (figure 3 gate delays for 8input OR) Total delay is 13 gates
Note (Synchronous Mealy) we want to latch the output of legal! What about the edges and corners? More later
CS 150 Spring 2008 Lec #22: Othello Design Example - 24
How much logic in a cell? 8x2 AND gates for remote = 16 8x2 OR gates for localOrRemote = 16
3 gates for leaf of legal computation (8 leaves), so 8x3 = 24 7 OR gates + 1 AND gate for rest of legal computation
Total 64 gates/cell (so far) Also need at least 2 latches for color + one for legal More logic to come
CS 150 Spring 2008 Lec #22: Othello Design Example - 25
Doing The Move This is easyOne external select (keyed by button or multiplexer from joystick not our problem today) Select & legal (previously computed)
Still have to flip
CS 150 Spring 2008 Lec #22: Othello Design Example - 26
FlippingMove
Flip
How can we build a flip function?CS 150 Spring 2008 Lec