Computer Science Canada tic tac to assignment help |
Author: | NovaK [ Mon Feb 01, 2016 4:37 pm ] | ||
Post subject: | tic tac to assignment help | ||
What is it you are trying to achieve? <Replace all the <> with your answers/code and remove the <>> What is the problem you are having? <The program is suppose to play tic atc toe you against a computer the computers logic is flawed its suppose to cehck if it can defend a move such as blocking the human from winning example would be placing at spot 2 if 1 and 3 are full. then its suppose to play if it cant defend it is really broken because it does not play at all it willdo 1 move after the human move then it breaks it alo sometimes places over things> Describe what you have tried to solve this problem <Tried looking at the code im really stumped still pertty new with programming> Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) <Answer Here>
Please specify what version of Turing you are using <4.1.1> http://s000.tinyupload.com/index.php?file_id=14942235473859021802 if u wanna dload it thx for the help fyi this is for a school course im only posting here because my teacher has not emailed me back its been 2 weeks ![]() |
Author: | Insectoid [ Mon Feb 01, 2016 6:06 pm ] | ||||||
Post subject: | RE:tic tac to assignment help | ||||||
You've got a lot of code that does nothing here. Look at this loop. How many times will it execute?
What is the played variable? Does it need to exist? Can you accomplish what you're trying to do with it without using it? You have a lot of lines that look like this:
When will this ever return false? It won't. If a condition always returns true, then why have a condition at all? Your AI checks if the player has played, for example, squares 1 and 2, and will select square 3 if he has. But if never checks if square 3 was already played, so on its next turn it will play that square again, so it looks like it doesn't do anything. I strongly suggest you break up your big loop into a few procedures. A draw procedure, that draws the board and all of the x's and o's, a player turn procedure that processes the player's input and an AI procedure that controls the AI, so your main loop just looks like this:
This will make it much, much easier to read and debug. |
Author: | NovaK [ Wed Feb 03, 2016 3:00 pm ] |
Post subject: | Re: tic tac to assignment help |
Thanks for your reply i am using the played variable to tell if it is the computer that filled that spot or human so i know who to say wins and im putting it all into procedures and 1 big loop thx for the advice |
Author: | Insectoid [ Wed Feb 03, 2016 5:20 pm ] |
Post subject: | RE:tic tac to assignment help |
Doesn't the variable squares store who filled that spot? |