Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please only answer in c# language. In this program you will design and implement a class that allows a person to play a two player

image text in transcribed

please only answer in c# language.

In this program you will design and implement a class that allows a person to play a two player game of tic-tac-toe on a 3x3 grid that is a 3x3 array of integers. The default constructor should initialize all board values to the integer zero (0). When player 1 moves you should place a one (1) in the position of the array they choose to move to and when player 2 moves you should place a two (2). Each move must be to an empty square and the program should be able to correctly display when a win is achieved and who the winner is.

After each move you should display the new board to the user and it should correctly show the position of each players pieces. The input of position should be by letter and number so the grid will be mapped like the image below and an entry of A0 would place a value in the top left corner, A1 in the top middle, A2 in the far right top and so on. The input of the game should be either from keyboard or detect the presence of a text file named game.txt in the root directory of the application, if an input file exists then you will run each game provided in the file until there are no more games to run, you will then write the array state out to a json string representation of the array for each game and then stop execution. You are not guaranteed of a clean input file so you must check to make sure the file contents are not malicious in nature and follow the pattern of the sample file posted. To write out the json string you will need to do some research on how to output an object (in this case your game board array) to a json string, I recommend looking up the library at this url https://www.newtonsoft.com/json because I find the implementation very straightforward, if you choose to use a different library make sure that you provide the .dll file for that library in your turn in code.

You will need to present a menu of some kind to the user so they can pick the options on how they want the game to run, how you implement this is up to you.

You should implement a dice roll or something to determine which human player starts first, or if the game is human vs computer which player starts first.

Error handling needs to be done gracefully so that the program does not terminate prematurely. Make sure you account for invalid input because you can never trust the user to follow your rules.

Extra credit: make a computer AI that the human user can play against, the more complex the ai is the more extra credit available for up to 20 points of assignment extra credit.

0

1

2

A

B

C

A sample input file is below

P1: A0

P2: A2

P1: B0

P2: C0

P1: B1

P2: B2

P1: C2

P2: A1

P1: C1

0000000000

P2: C0

P1: C1

P2: C1

P1: C1

P2: C3

P2: C2

Please note the input file has invalid values and player 2 tries to cheat by going twice, you must keep track of all of these scenarios and handle them correctly, DO NOT TERMINATE THE GAME, just make sure that you handle bad events and not allow them to occur. The end of a game in the file will be denoted by the string 0000000000 and then a new game will begin.

As always you are expected to work on this assignment by yourself and if you use any external resources to document them in your code.

Turn in a fully documented .cs files, zipped into a file named with your lastname and redid.zip so for example mine would be amack123456789.zip to blackboard by the turn in time to receive credit. Make sure your class file is fully commented and that your name is included in the file. Blackboard will be set to only allow one submission so make sure you follow directions completely to receive full credit. Resubmissions will not be allowed. Reminder all work must be submitted to receive a passing grade in this course.

Clarification posted for programming assignment 2

Posted on: Thursday, September 28, 2017 5:36:09 PM PDT

I made a few small changes to the assignment 2 specification. Notably You need to implement a way to determine who goes first in a human vs human game or human vs computer. When you handle exceptions you need to gracefully handle them and not terminate code execution but allow the players to continue. When you output your json file you probably should write a newline to the file so the json strings are not all shoved together you can do this by File.WriteAllText("filename.txt"," "); this will append a newline character to the end of your file. Please review the word document for all specifications.

P1:A0 P2: A2 P1: BO In this program you will design and implement a class that allows a person to play a two player game oftic-tac-toe on a 3x3 grid that is a 3x3 array of integers. The default constructor should initialize all board values to the integer zero (0). When player 1 moves you should place a one (1) in the position of the array they choose to move to and when player 2 moves you should place a two (2). Each move must be to an empty square and the program should be able to correctly display when a win is achieved and who the winner is. P1: B1 P2: B2 P1: C2 P2: A1 P1: C1 After each move you should display the new board to the user and it should correctly show the position of each players pieces. The input of position should be by letter and number so the grid will be mapped like the image below and an entry of A0 would place a value in the top left corner, Al in the top middle, A2 in the far right top and so on. The input of the game should be either from keyboard or detect the presence of a text file named gams..m the root directory of the application, if an input file exists then you will run each game provided in the file until there are no more games to run, you will then write the array state out to a json string representation of the array for each game and then stop execution You are not guaranteed of a clean input file so you must check to make sure the file contents are not malicious in nature and follow the pattern of the sample file posted. To write out the json string you will need to do some research on how to output an object (in this case your game board array) to a json string, I recommend looking up the library at this url https:/www.newtonsoft.com ison because I find the implementation very straightforward, if you choose to use a different library make sure that you provide the dll fle for that library in your turn in code. P2: C3 P2: C2 You will need to present amenu of some kind to the user so they can pick the options on how they want the game to run, how you implement this is up to you. Please note the inputfile has invalid values and player 2 tries to cheatby going twice, you mustkeep trackof all of these scenarios and handle themcorrectly, DO NOTTERMINATE THE GAME, just make sure that you handle bad events and notallowthem to occur. The end of a game in the file will be denoted by the string 0000000000" and thena newgame will begin. You should implement a dice oll or something to determine which human player starts first, or if the game is human xs computer which player starts first. Error handling needs to be done gracefully so that the program does not terminate prematurely. Make sure you account for invalid input because you can never trust the user to follow your Extra credit: make a is the more extra credit available for up to 20 points of assignment extra credit Turn in a fully documented files, zipped into a file named with your lastoaM& and redid zip so for example mine would be amack123456789 zipto blackboard by theturn in time to receive credit. Make sure your classfile is fully commentedand that your name is included in the file. Blackboardwill be set to only allow one submission so make sure you follow directions completelyto receive full credit Resubmissions will notbe allowed. Reminder all work must be submitted to receive a passing erade in this course. Clarification posted for programming assignment 2 Postad o Theeadry, Soptamber 2, 2017 3:3: PNPDT I mad e te w small changes to the assignment 2 speciscation Notably you sead o implemenra way so datennise who goes tist n huram, homm p me oc humm compuet when you brdle exceptions you need so pracefully handle them md not txr","n"); this will to the ile so thejscastrings are mot all shoved togehe you can do this by ppend anliza chancter to the nd of your file. Plana the word docman: for all pscitcatioa A sample input file is below

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions