Homework2

Homework2 - CS 130 Homework 2 2.1 Kevin Deggelman May 4,...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 130 Kevin Deggelman May 4, 2009 Homework 2 2.1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2.2 2.3 /* Part 1 The design pattern used to solve this problem is a recursive  program that has inputs of the representation of the board, and whose turn it is. The  program makes all possible moves at each step, and keeps track of the percentage of time that move  leads to a victory. */ class  BoardRepresentation { } class  Player { boolean   isTurn ; void  setTurn( boolean  bool) {
Background image of page 2
isTurn  = bool; } } int  makeMove(BoardRepresentation theBoard, Player player1, Player player2  ) { int  winPercentage; //Choose a move, update the board, and call make move BoardRepresentation newBoard; if (player1. isTurn  ==  true ) { player1.setTurn( false ); player2.setTurn( true ); } else  { player1.setTurn( true ); player2.setTurn( false ); } return  winPercentage + makeMove(newBoard, player1, player2); } /* Part 2 To solve this problem, we will use inheritance to give special 
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

Homework2 - CS 130 Homework 2 2.1 Kevin Deggelman May 4,...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online