Home / Expert Answers / Computer Science / in-python-please-in-python-please-section-6-final-project-part-2-building-an-ai-player-n-pa771

(Solved): In python please! In Python please! Section 6: Final Project Part 2 - Building an AI Player n ...



In python please!

Section 6: Final Project Part 2 - Building an AI Player
n this section you will implement a sequence of computer players (AI)ming Your Code:
Like part 1, there is a tester file you should run to see if it finds any errors in the code. It will test th

\# Part 2: AI Functions \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\

In Python please!

Section 6: Final Project Part 2 - Building an AI Player n this section you will implement a sequence of computer players (AI) starting with a simple player working toward a nore intelligent player. Each of your functions should return a column number indicating where you want to play the urrent block. mplement the following functions: play_vertical_matcher(block, board) Given: 'block' which is a number that is a positive power of 2, and 'board' which is a table of integers Return: a column index where the topmost block will match if possible, otherwise return a random column that is not full For game play: given the current block and board, play in a column where the block matches the topmost block (if possible), otherwise play randomly, avoiding full columns. play_better_vertical_matcher(block, board) Given: 'block' which is a number which that is a positive power of 2 , and 'board' which is a table of integers Return: a column index where the topmost block will match if possible, otherwise return a column index that will stack a lower number on top of a higher number if possible, otherwise return a random column that is not full For game play: given the current block and board, play in a column where the block matches the topmost block (if possible). If there are no matches, then play on top a block that is larger in value (i.e., 4 can be played on top of anything \( >4 \) ), otherwise play randomly avoiding full columns. play_my_awesome_logic(block, next_block, board) Given: 'block' which is a number that is a positive power of 2, 'next_block' which a number that is positive power of 2 representing the tile to play after block, and 'board' which is a table of integers Return: a column index For game play, given the current block, next block, and current board develop a computer player that is better than any of the players described above. Add a block comment to the top of the function that explains your strategy and "why it is awesome". Even though you are given the on_deck parameter for play_my_awesome_logic (), you do not have to use it ifyou have a different approach. It's there in case you want to use it. You do not have to follow the sequence of computer players (vertical matchers) for play_my_awesome_logic (). You can implement a completely new idea to improve the computer player ifyou want. The board argument is an exact copy of the actual game board. That means you are allowed to change the board in your AI code since it will not affect the actual game board. This might be helpful when designing a new approach. ming Your Code: Like part 1, there is a tester file you should run to see if it finds any errors in the code. It will test the vertical_matcher and the better_vertical_matcher but not your awesome logic player. For both testing and debugging, it will also be helpful to run the game using your new play strategies. To do this, look at the strategy function in ai.py. This function has commented lines that call one of the many playing functions. The first playing function is called play_console_control, which allows you to play by typing. To run the game with your new random players, first add a comment character to the line that calls play_console_control function, and delete the comment character on the line that calls the function you want to test. Using an automatic player to play the game means the game will be over immediately and gush out a bunch of output. It is much easier to follow if you pause between every move so you can follow the game. To do that, remove the comment character from the line that calls the input function. Then, the game will pause until you hit a key to see the next move. \# Part 2: AI Functions \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# def play_vertical_matcher(block, board):| def play_better_vertical_matcher(block, board): pass def play_my_awesome_logic(block, next_block, board): pass \# Given Functions \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# \# play interactively \( -- \) this code is complete \( - \) - no changes needed def play_console_control(block, board): num_cols \( =\operatorname{len}( \) board [0] ) col \( = \) int(input("Drop" \( + \) str(block) \( + \) " in which column: ")) \# ask again if given an invalid column while col \( <0 \) or col >= num_cols: col = int(input("Drop" \( +\operatorname{str}( \) block) \( + \) " in which column: ")) return col \# uncomment one line -- this is the strategy used to play the game def strategy(block, next_block, board): input() \# uncomment to pause the loop between every board update return play_console_control(block, board) \# interactive \#return play_vertical_matcher(block, board) \#return play_better_vertical_matcher(block, board) \#return play_my_awesome_logic(block, next_block, board) if _-_name \( == \) "_-main__": block 2048.main()


We have an Answer from Expert

View Expert Answer

Expert Answer


play_vertical_matcher (block, board) Given: 'block' which is a number that is a positive power of 2, and 'board' which is a table of integers Return:
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe