0% found this document useful (0 votes)
4 views

Assignment 3

The assignment requires creating a board game with a 4x4 grid for two players: a computer and a user. Players take turns selecting positions, with the computer making random moves, and the game checks for winning combinations after each turn. Functions should be implemented to manage the game flow, including printing the board, checking for winners, and validating user input.

Uploaded by

singh.angad0905
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Assignment 3

The assignment requires creating a board game with a 4x4 grid for two players: a computer and a user. Players take turns selecting positions, with the computer making random moves, and the game checks for winning combinations after each turn. Functions should be implemented to manage the game flow, including printing the board, checking for winners, and validating user input.

Uploaded by

singh.angad0905
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Assignment 3

Objective:

• To have a better understanding of list


• Practice use random module.
• Practice using functions, loops and if statement.

Requirements: Create a board game and the board looks like this

-------------------------
| 1 | 2 | 3 | 4 |
-------------------------
| 5 | 6 | 7 | 8 |
-------------------------
| 9 | 10 | 11 | 12 |
-------------------------

| 13 | 14 | 15 | 16 |

-------------------------

This board game has the following rules:

1. The game has two players: computer & user of the program, computer will randomly select the
position for its move. You can use your own choice of symbols to represent computer or user, for
example, “X” for user and “O” for computer.

2. Use list to store the board items and available positions; both lists contain the same items in the
beginning of the game; [ “1 “, “2 “, “3 “, “4 “, “5 “, “6 “, “7 “, “8 “, “9 “, “10”, “11”, “12”, “13”, “14”,
15”, “16”].

3. The program will randomly select who will make first move (computer or the user).

4. User can choose any available positions, computer will randomly select from the available positions;
after a position is chosen, your program should remove the position item from available list and
change the position item in board list to the symbol representing computer/user. If we use “X” to
represent user and “O” to represent computer; in the first move, if it’s user’s turn (randomly
selected in requirement 3) and user chooses “12”, then the two lists will be as shown below

available = [ “1 “, “2 “, “3 “, “4 “, “5 “, “6 “, “7 “, “8 “, “9 “, “10”, “11”, “13”, “14”, 15”, “16”]

board = [ “1 “, “2 “, “3 “, “4 “, “5 “, “6 “, “7 “, “8 “, “9 “, “10”, “11”, “X”, “13”, “14”, 15”, “16”]


In the second move, it’s computer’s turn and computer randomly selected chooses “7”, then

available = [ “1 “, “2 “, “3 “, “4 “, “5 “, “6 “, “8 “, “9 “, “10”, “11”, “13”, “14”, 15”, “16”]

board = [ “1 “, “2 “, “3 “, “4 “, “5 “, “6 “, “O “, “8 “, “9 “, “10”, “11”, “X”, “13”, “14”, 15”, “16”]

5. There are totally 14 winning combinations: (1, 2, 3, 4) (5, 6, 7, 8) (9, 10, 11, 12) (13, 14, 15, 16) (1, 5,
9, 13) (2, 6, 10, 14) (3, 7, 11, 15) (4, 8, 12, 16) (1, 6, 11, 16) (4, 7, 10, 13) (2, 7, 12) (3, 6, 9) (5, 10, 15)
(8, 11, 14)
Once there is a winning combination, the game is finished, and the winner will be declared.

6. Use functions to simplify your job, for example, create functions to print the board, to check winner,
to validate user’s choice, etc. print the board will print out the how the board look like after each
move; check winner will check whether there is a winner after each move; validate user’s choice will
make sure if user only choose one of the available position, otherwise prompt the user to choose
again.

7. Computer and user will move in turn after the first move.

8. If after all positions are taken and still there is no winner, then it’s a tie.

You might also like