Solved by Expert Tutors
Make sure you provide comments including the file name, your name, and the date at the top of the file you submit. Also make sure to include...
Solved by Expert Tutors
Question

# i need help coding these two functions found in the directions in

the attachment. It is for a game called hexapawn. its python programming. will tip well, need it asap.

Programming Assignments 6 and 7 - Hexapawn ECS 10 - Summer 2016 All solutions are to be written using Python 3. Make sure you provide comments including the file name, your name, and the date at the top of the file you submit. Also make sure to include appropriate docstrings for all functions. The names of your functions must exactly match the names given in this assignment. The order of the parameters in your parameter list must exactly match the order given in this assignment. For any given problem below, you will want to write additional functions other than those specified for your solution. That's fine with us. Hexapawn is played on a 3 x 3 chessboard. The two players face each other across the board. Each player begins with three either three white pawns or three black pawns, placed one to a square in each of the three squares nearest that player. The player with the white pawns moves first. A player may choose to move one of his or her pawns in one of these ways: A pawn may be moved one square forward to an empty square A pawn may be moved one square diagonally forward to a square occupied by an opponent's pawn. The opponent's pawn is then removed. The players alternate moving pawns until one of the players wins. A player wins when: A player's pawn has advanced to the other end of the board. The opponent has no pawns remaining on the board. It is the opponent's turn to move a pawn but is unable to do so. As envisioned by its inventor, Martin Gardner, hexapawn was intended to be played with only six pawns on a 3 x 3 board. Now, however, we are extending the definition of hexapawn to include any similar game involving n white pawns, n black pawns, and a n x n board. Over the next week, you are to construct the core functionality necessary for a computer program to play this game. For this program, the current state of the game (i.e., the board) is represented as a list of lists. In the list of lists, the first sublist is the top row of the board, and the last sublist is the bottom row of the board. A 0 is an empty square, a 1 is a white pawn on the square, and a 2 is a black pawn on the square.
For example, a board that looks like this when displayed on your monitor: - w w w - - b b b will be represented in your program like this: [[0,1,1],[1,0,0],[2,2,2]] The core functionality that you will provide will take the form of two functions. The first function is the move generator, called generateMoves . This function expects two arguments. The first argument indicates the color of the pawns that your program is moving: 1 indicates that your program controls the white pawns, and 2 says that your program controls the black pawns. The second argument is a list of lists representing the current board. Your function returns a list of the possible new boards that can result from the current board in one move. For example, if your program controls the black pawns, and the current board is the board shown above, then your generateMoves function should behave like this: >>> board = [[0, 1, 1], [1, 0, 0], [2, 2, 2]] >>> generateMoves(2, board) [[[0, 1, 1], [2, 0, 0], [2, 0, 2]], [[0, 1, 1], [1, 2, 0], [2, 0, 2]], [[0, 1, 1], [1, 0, 2], [2, 2, 0]]] As this example illustrates, black has three legal next moves given the current board. Your function should generate all three of these moves, but they won't necessarily appear in the same order as in this example, depending on how your function computes the possible next moves. The second function is called chooseBestMove and expects two arguments. As with the previous function, the first argument indicates the color of the pawns controlled by your program. The second argument is a list of possible next moves returned by your generateMoves function. Your chooseBestMove function evaluates each of the boards/moves in the second argument and returns the best one. That board is your program's next move and becomes the new current board. Here's an example of how this function should behave: >>> board = [[0, 1, 1], [1, 0, 0], [2, 2, 2]] >>> mlist = generateMoves(2, board) >>> mlist [[[0, 1, 1], [2, 0, 0], [2, 0, 2]], [[0, 1, 1], [1, 2, 0], [2, 0, 2]], [[0, 1, 1], [1, 0, 2], [2, 2, 0]]] >>> chooseBestMove(2, mlist) [[0, 1, 1], [2, 0, 0], [2, 0, 2]]
Show entire document
##prog67.py ##Allison Tearjen ## July 23,2016 ## ##write two functions that generate and pick the most optimal next move given an intial board and color pawn to move def generateMoves(color,current_board): possible_moves=[] empty=0 for row in current_board: one_move=[[0,0,0],[0,0,0],[0,0,0]] for item in row: if item==color and color==1: #6 different possiblitlies where white could be during the game if current_board[0][0]==1: if current_board[1][0]==0: one_move.append(item) elif current_board[1][1]==2: one_move.append(item) one_move[0][0]==empty elif current_board[0][1]==1: if current_board[1][1]==0: one_move[1][1]=1 elif current_board[1][0]==2: one_move[1][0]=1 elif current_board[1][2]==2: one_move[1][2]=1 one_move[0][1]=empty elif current_board[0][2]==1: if current_board[1][2]==0: one_move[1][2]=1 elif current_board[1][1]==2: one_move[1][1]=1 one_move[0][2]=empty elif current_board[1][0]==1: if current_board[2][0]==0: one_move[2][0]==1 elif current_board[2][1]==2: one_move[2][1]==1 one_move[1][0]=empty elif current_board[1][1]==1: if current_board[2][1]==0: one_move[2][1]==1 elif current_board[2][0]==2: one_move[2][0]==1 elif current_board[2][2]==2: one_move[2][2]==1 one_move[1][1]=empty elif current_board[1][2]==1: if current_board[2][2]==0: one_move[2][2]==1 elif current_board[2][1]==2: one_move[2][1]==1 one_move[1][2]=empty
possible_moves.append(one_move) return possible_moves

lest

nec facilisis. Pellentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque dapibus ef

cing elit. rem ipsum dolor s risus ante, dap it sum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortor nec , ultrices ac magna. Fusce dui lect lestie

### Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

• ### -

Study Documents

Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

Browse Documents