30 likes | 127 Views
scoresFor(self , board, ox, ply) Make empty score list For each col : If allowed, add a move into the col for ox, then: Check for a win, if yes, append score of 100 to the list This is easy, call winsFor () Otherwise, if ply is 1, append score of 50 to the list Otherwise:
E N D
scoresFor(self, board, ox, ply) • Make empty score list • For each col: • If allowed, add a move into the col for ox, then: • Check for a win, if yes, append score of 100 to the list • This is easy, call winsFor() • Otherwise, if ply is 1, append score of 50 to the list • Otherwise: • Obtain opposing checker character • If ox is ‘x’ use ‘o’, if ox is ‘o’ use ‘x’ • Get a list of scores for the current board for opponent • Big Idea: call scoresFor recursively with ply - 1 • Find the maximum score in the list (best move for opponent) • Append 100 – max opponent score to the list • If a move was added, delete it • If the move not allowed, append score of -1 to the score list • Return the list
nextMove(self, board) • Get a list of scores for all the moves I can make • Use scoresFor() with my own checker character • You will have a score in the list where the index of the list element is the column number for the move • Determine the highest score in the list • There may/will be more than one high score • Pick a column number corresponding to one of the high scores (leftmost, rightmost, random?) • Return the chosen column number to the caller