def find_star_in_board(board): x, y = [-1, -1] for i in range(len(board)): for j in range(len(board[i])): if board[i][j] == '*': # find * positions x = i y = j break return [x, y] def replace_in_board(board, x, y, x_new, y_new): if 0 <= x_new < len(board) and 0 <= y_new < len(board): if board[x_new][y_new] == 'F' or board[x_new][y_new] == '.': board[x_new][y_new] = '*' board[x][y] = '.' return [x_new + 1, y_new + 1] elif board[x_new][y_new] == 'W': return [-1, -1] elif board[x_new][y_new] == 'O': board[x_new][y_new] = 'X' board[x][y] = '.' return [x_new + 1, y_new + 1] else: return [-1, -1] def move_up(board): [x, y] = find_star_in_board(board) return replace_in_board(board, x, y, x - 1, y) def move_down(board): [x, y] = find_star_in_board(board) return replace_in_board(board, x, y, x + 1, y) def move_left(board): [x, y] = find_star_in_board(board) return replace_in_board(board, x, y, x, y - 1) def move_right(board): [x, y] = find_star_in_board(board) return replace_in_board(board, x, y, x, y + 1) def move(board, direction): if direction == 'U': return move_up(board) elif direction == 'L': return move_left(board) elif direction == 'R': return move_right(board) elif direction == 'D': return move_down(board) def main(): board1 = [['.', '.', '.', '.', 'W'], ['.', '.', '.', '.', '.'], ['.', 'F', '.', 'F', '.'], ['.', '*', 'O', '.', 'W'], ['.', '.', 'O', '.', '.']] print(board1) print(move(board1, 'R')) print(board1) if __name__ == '__main__': main()
Python programming Part VI: Move Starman by Movement Commands (20 points) Write a function move ()...
Python Programming: Why do I get UnboundLocalError? What does this mean and how can I fix it? Question: Write a function check_move(column, row) which returns a string describing a chess move to a given row and column on the chess board. Your program must check if the row and column entered are both valid. The column in a chess board is a letter ranging from A to H or a to h (inclusive) and the row is a number between...
IrmaMoves.h : #include "IrmaMoves.h" typedef struct Move { Irma irma; // an instance of Irma L Location from_loc; // location where Irma is moving from Location current_loc; // location where Irma is passing over Location to_loc; // location where Irma is moving to } Move; typedef struct Location { char col; // the square's column ('a' through 'h') int row; // the square's row (0 through 7) } Location; typedef struct Irma { int ws; // wind speed (MPH) int...
In problem 3, you will write a function, findvertically (), which will determine whether or not a given word exists in a word search puzzle vertically. In word search puzzles, words can be written upwards or downwards. For example, "BEAK" appears at [1] [3] written downwards, while "BET" appears at [2] [2] written upwards: [["C", "A", "T", "X", "R"], ["D", "T", "E", "B", "L"], ["A" "R" "B", "E", "Z"], ["X", "O", "E", "A", "U"], ["J", "S", "O", "K", "W"]] Your...
Python Programming Task 2: Leap Years Part A - Is this a leap year? Write a function is leap year(year) that calculates whether a given (CE) year is a leap year. The function must: • take one argument: a positive integer representing a year (assumed to be CE) • return True if that year was a leap year; return False if not NOTE: all years that are divisible by four are leap years, unless they are also divisible by 100,...
Write a class named FBoard for playing a game... PLEASE USE C++ PLEASE DO NOT USE "THIS -->". NOT ALLOWED PLEASE PROVIDE COMMENTS AND OUTPUT! Write a class named FBoard for playing a game, where player x is trying to get her piece to row 7 and player o is trying to make it so player x doesn't have any legal moves. It should have: An 8x8 array of char for tracking the positions of the pieces. A data member...
Use python!!! need to match the execution result that is provided. Part One – Keyword Arguments and Default Values Write an invoice function. The function will generate a simple invoice and will have two required arguments and two keyword arguments. The two required arguments are unitPrice and quantity. The first keyword argument is shipping, and it has a default value of 10. The second keyword argument is handling, and it has a default value of 5. Test it twice from...
Use python!!! need to match the execution result that is provided. Part One – Keyword Arguments and Default Values Write an invoice function. The function will generate a simple invoice and will have two required arguments and two keyword arguments. The two required arguments are unitPrice and quantity. The first keyword argument is shipping, and it has a default value of 10. The second keyword argument is handling, and it has a default value of 5. Test it twice from...
In C++. Write a class named FBoard for playing a game, where player x is trying to get her piece to row 7 and player o is trying to make it so player x doesn't have any legal moves. It should have: An 8x8 array of char for tracking the positions of the pieces. A data member called gameState that holds one of the following values: X_WON, O_WON, or UNFINISHED - use an enum type for this, not string (the...
Can someone please complete the "allTheQueensAreSafe" function? #include <stdio.h> #include <stdlib.h> void printBoard(int *whichRow, int n) { int row, col; for (row = 0; row < n; row++) { for (col = 0; col < n; col++) { printf("%c", (whichRow[col] == row) ? 'Q' : '.'); } printf("\n"); } printf("\n"); } int allTheQueensAreSafe(int *whichRow, int n, int currentCol) { // TODO: Write a function that returns 1 if all the queens represented by // this array are safe (i.e., none...
Please develop the following code using C programming and using the specific functions, instructions and format given below. Again please use the functions given especially. Also don't copy any existing solution please write your own code. This is the first part of a series of two labs (Lab 7 and Lab 8) that will complete an implementation for a board-type game called Reversi (also called Othello). The goal of this lab is to write code that sets up the input...