当前位置:天才代写 > C++/C代写,c语言代写代考-100%安全,包过 > Tic-Tac-Toe代写 游戏代写实现NWEN 241 Assignment 2

Tic-Tac-Toe代写 游戏代写实现NWEN 241 Assignment 2

2018-10-09 08:00 星期二 所属: C++/C代写,c语言代写代考-100%安全,包过 浏览:1917

Tic-Tac-Toe代写 In this assignment, you will create 3 different implementations of the “Tic- Tac-Toe” game in 3 tasks

 

 

NWEN 241 Assignment 2

“Tic-Tac-Toe”

Release Date: 24 Sep 2018, 23:59

Submission Deadline: 10 OCT 2018, 23:59

 

In this assignment, you will create 3 different implementations of the “Tic- Tac-Toe” game in 3 tasks:

 

Tic-Tac-Toe代写
Tic-Tac-Toe代写

1D Implementation – a simple implementation of the game for two players using only ’X’-es. The first player who succeeds in placing 3 consecutive ’X’-es in a row wins the game.

2D Implementation – a game for two players, ’X’ and ’O’, who take turns marking the spaces in a n n grid. The first player who succeeds in placing 3 consecutive ’X’-es (or ’O’-s) in a horizontal, vertical, or diagonal (also antidiagonal) row wins the game.

Human vs Computer – 2D implementation but instead of 2 human players, the second player is the computer.

 

Your answer to each of the tasks which will be assessed individually.

 

Instructions and Submission Guidelines:

 

You must write C programs to solve each of the tasks. Each C pro- gram must be saved as a .c file and must be named using the con- vention t{task number}.c. For example, the program for Task 1 should be named as t1.c. Similarly, t2.c should be the solution for Task 2, and so on.

You should provide appropriate comments to make your source code readable. Otherwise, if your code does not work and there are no comments, you may lose all the marks!

You must submit the files on or before the submission deadline to this

website: https://apps.ecs.vuw.ac.nz/submit/XMUT241/Assignment_

2. Late submissions may not be marked.

 

 

Assessment Criteria:

 


Correctness: The program must satisfy all the functional require- ments explicitly stated in the task. It must provide the correct output for every expected/valid input. (Approximately 50% of the marks.)


Completeness: The program must satisfy all the functional require- ments implicitly stated in the task. It must be able to handle all unex- pected inputs and not terminate abnormally. (Approximately 15% of the marks.)

Readability: The source code must be readable, through the use of proper indentation, and sufficiently commented. (Approximately 15% of the marks.)

“Compilability”: The program must compile without warnings. (Ap- proximately 20% of the marks.)

 

Task 1.

[30 Marks]

In the first task, you have to write a program that for a 1D implementation of the game. In this simple implementation, two players take turns to mark the array with the ’X’ character. The player to first make 3 ’X’-es side-by- side in the array wins the game. The main goal here is to create the basic functionality of the game on which you can later build in Task 2.

To build your program, you must follow the guidelines below.

Function Prototypes

First create a function which outputs (prints) the state of the field (1D array). To achieve this, you have to use the following function prototype:


 

 

void draw_field(const char field[], int size)

 

The size of the field is entered by the user and must be at least 3 and at most

64. All the fields (positions) of the array will be initialised with a space (’ ’). Here is a sample output for the function:


 

 

$ ./tictactoe

Enter the size of field: 9

 

 

+-+-+-+-+-+-+-+-+-+

| | | | | | | | | |


+-+-+-+-+-+-+-+-+-+ 1 2 3 4 5 6 7 8 9

 


Create another function which puts an ’X’ character at the position selected (entered) by the user. The function prototype for this function is the follow- ing:

 

int add_cross(char field[], int size, int position)

 

If the selected position is already in use (there is an ’X’ character) the func- tion will return 0. Otherwise (i.e. the position is still free), the function will return 1. If the entered position is outside the field, the function will return

-1.

 


 

 

Player A: 2

+-+-+-+-+-+-+-+-+-+

| |X| | | | | | | |

+-+-+-+-+-+-+-+-+-+ 1 2 3 4 5 6 7 8 9

 

 

Player B: 5

+-+-+-+-+-+-+-+-+-+

| |X| | |X| | | | |

 


 

+-+-+-+-+-+-+-+-+-+ 1 2 3 4 5 6 7 8 9

 

 

 


 


Now you have to implement another function to detect whether the game is already solved (won). To achieve this, you have to use the following function prototype:

 

int is_solved(const char field[], int size)

 

This function will return 1 if there is a min. number of 3 consecutive ’X’ characters (next to each other) in the field. Otherwise the function will return 0. With the functions above, finish the implementation of the game. Here is a sample output:

 

 

 

$ ./tictactoe

Enter the size of field: 9

+-+-+-+-+-+-+-+-+-+

| | | | | | | | | |

+-+-+-+-+-+-+-+-+-+ 1 2 3 4 5 6 7 8 9

Player A: 2

+-+-+-+-+-+-+-+-+-+

| |X| | | | | | | |

+-+-+-+-+-+-+-+-+-+ 1 2 3 4 5 6 7 8 9

Player B: 5

+-+-+-+-+-+-+-+-+-+

| |X| | |X| | | | |

+-+-+-+-+-+-+-+-+-+ 1 2 3 4 5 6 7 8 9

Player A: 9

+-+-+-+-+-+-+-+-+-+

| |X| | |X| | | |X|

+-+-+-+-+-+-+-+-+-+ 1 2 3 4 5 6 7 8 9

Player B: 10 Wrong position! Player A: 2

X is already there! Player B: 8

+-+-+-+-+-+-+-+-+-+

| |X| | |X| | |X|X|

+-+-+-+-+-+-+-+-+-+ 1 2 3 4 5 6 7 8 9

Player A: 7

+-+-+-+-+-+-+-+-+-+

| |X| | |X| |X|X|X|

+-+-+-+-+-+-+-+-+-+ 1 2 3 4 5 6 7 8 9


 

Player A won!

 

 

 

 

Task 2.

[60 Marks]

Now you have to create the 2D implementation of the game. Implementa-

 

 

tion guidelines:

 

• You will use a 2D array instead of 1D.

The game field (grid) have to be of a square shape, i.e. it will have the same number of rows as columns. The minimum size of the field is 3

× 3 and its maximum size is 64 × 64.

• The two players will take turns entering two values at a time:

– The first is the X coordinate – the row number where the value will be inserted.

– The second is the Y coordinate – the column number where the value will be inserted.

The rows are numbered from LEFT to RIGHT starting with 1! The row numbers are showed at the bottom of the grid.

The columns are numbered from BOTTOM to UP starting with 1! The column numbers are showed at the left side of the grid.

Player A is playing with the ’X’ character while Player B is playing with the ’O’ character.

All the fields (positions) of the array will be initialised with the space character (’ ’).

 

Sample output of the dialog between the players is the following:

 


 

 

$ ./tictactoe

Enter the size of field: 5

+-+-+-+-+-+

5 | | | | | |

+-+-+-+-+-+

4 | | | | | |

+-+-+-+-+-+

3 | | | | | |

+-+-+-+-+-+

2 | | | | | |

+-+-+-+-+-+

1 | | | | | |

+-+-+-+-+-+ 1 2 3 4 5

 

 

Player A: 0 3 Wrong position! Player B: 3 3

+-+-+-+-+-+

5 | | | | | |

+-+-+-+-+-+

4 | | | | | |

+-+-+-+-+-+

3 | | |O| | |

+-+-+-+-+-+

2 | | | | | |

+-+-+-+-+-+

1 | | | | | |

+-+-+-+-+-+ 1 2 3 4 5

Player A: 2 2

+-+-+-+-+-+

5 | | | | | |

+-+-+-+-+-+

4 | | | | | |

+-+-+-+-+-+

3 | | |O| | |

+-+-+-+-+-+

2 | |X| | | |

+-+-+-+-+-+

1 | | | | | |

+-+-+-+-+-+ 1 2 3 4 5

Player B: 4 4

+-+-+-+-+-+

5 | | | | | |

+-+-+-+-+-+

4 | | | |O| |

+-+-+-+-+-+

3 | | |O| | |

+-+-+-+-+-+

2 | |X| | | |

+-+-+-+-+-+

1 | | | | | |

+-+-+-+-+-+ 1 2 3 4 5

Player A: 6 5 Wrong position! Player B: 5 5

+-+-+-+-+-+

 

 

5 | | | | |O|

+-+-+-+-+-+

4 | | | |O| |

+-+-+-+-+-+

3 | | |O| | |

+-+-+-+-+-+

2 | |X| | | |

+-+-+-+-+-+

1 | | | | | |

+-+-+-+-+-+ 1 2 3 4 5


Player B won!

 

 

Function Prototypes

To implement the game you have to use the following function prototypes:


 

 

void draw(int size, const char field[][size])

 

where, size is the number of rows and columns, and field is a 2D array. This function will print the grid in the following direction:

 

• The rows will be printed from LEFT to RIGHT starting with 1!

• The columns will be printed from BOTTOM to UP starting with 1!

The next prototype is the following:


 

 

int add_cross(int size, char field[][size], char player,


 

int x, int y)

 

 

where size is the number of rows and columns, field is a 2D array. The parameters x and y represent the horizontal and vertical coordinates, re- spectively, where the player’s value will be inserted. The player parameter represents the actual player (A or B).

Your last function prototype is the following:


int is_solved(int size, const char field[][size])

 

where size is the number of rows and columns, and field is the 2D array. This function will determine whether the game is already solved (won),

 

 

i.e. whether are there 3 adjacent ’X’-s or ’O’-s. You have to check this in 4 directions:

 

• Horizontal

• Vertical

• Main diagonal

• Antidiagonal

 

Task 3.

[15 Marks]

Create another function with the following prototype:


void make_turn(int size, char field[][size])

 

 

This function will serve as the computer opponent to the human player. This means that in this function you will implement the computer logic

– it will put an ’X’ (or ’O’, you can decide the user will play with which character) at a random VALID (not in use) position in the grid.

最先出自天才代写 cs代写 作业代写 代写c
合作:幽灵代写
 

天才代写-代写联系方式