sing algebraic notations for indexing the positions in the board, with A,B,C indexing the columns and 1,2,3 the rows. Specifically, these coordinates would be used in the implementation for moves made by a human player. If the X X O Figure 1: Sample board position same token appears 3 times in any of the three columns, three rows or two main diagonals the game is over and that player wins. If the grid is filled without that happening the game is a dra

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

IN HASKELL PROGRAMMING LANGUAGE PLEASE

 

 

In case you do not know it: the game is played on a 3x3 grid that is initially empty. Two players are playing, by alternatingly making moves. A move by a player places their token (an X for player 1, an O for player 2) into a cell that was empty. We are using algebraic notations for indexing the positions in the board, with A,B,C indexing the columns and 1,2,3 the rows. Specifically, these coordinates would be used in the implementation for moves made by a human player. If the X X O Figure 1: Sample board position same token appears 3 times in any of the three columns, three rows or two main diagonals the game is over and that player wins. If the grid is filled without that happening the game is a draw. For the depicted board, we have Xs in positions C3 and A2, and an O in position B1. It would be O’s turn to make a move; a legal move would be C2, but it is not a good move, because X can force a win by responding A1. O cannot force a win, but B2 keeps the game balanced.

The Board and its Logic

1. Define appropriate types for a Board, a Move, and an Outcome. You can use algebraic types or type synonyms — this is your choice.

2. Define a function printBoard :: Board -> IO() that prints the board in a human-readable format. 1

3. Define a function of type Board -> Move -> Maybe Board that checks whether the move is legal in the board. If it is legal, the function should return the updated Board, otherwise Nothing.

4. Define a function of type Board -> Maybe Outcome, which returns the information about the outcome of the game: do we have a win for player X, a win for player O, a draw, or should the game continue? A return value of Nothing indicates that the game should continue.

Communications, Players and Processes

There are two kinds of communication messages going on in this game: the invitation to make a move (which will communicate a Board to a player), and the actual Move itself, which the player communicates to the game manager. There are three processes in every game: the game manager, and the two players. A player is either a bot, or a human player. A player has three parameters: their game token (O or X), an input channel to read move invitations and an output channel to write chosen moves.

5. Define the human player. When a move is requested from the human player, the board should be on display, and a move should be read from the keyboard. If the move is illegal an appropriate error message should be printed, and we try again. If the move is legal it should be send back on the player’s output channel.

6. Define a bot player. This player should make some legal move by just investigating the board. There should be an element of randomness (use the PickRandom module on moodle), unless there is only one “good” move. The bot does not have to be clever, but it could be.

7. Define the game managing process behaviour. This needs to keep track of the board position, the players’ input channels and whose turn it is. It should keep inviting the players in turn to make their moves, and announce a winner (or a draw) when the situation occurs. 8. Define a game start. This is an IO action parameterized by two players. This action should create the necessary channels, fork the player processes, and then continue managing the game. The purpose of the two parameters is to allow different match-ups (humans or bots vs. humans or bots).

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY