The cookie is used to store the user consent for the cookies in the category "Performance". This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". The cookie is used to store the user consent for the cookies in the category "Other. The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". The cookie is used to store the user consent for the cookies in the category "Analytics". These cookies ensure basic functionalities and security features of the website, anonymously. The list goes on, so just come up with a basic idea and it'll begin to take shape in code.Necessary cookies are absolutely essential for the website to function properly. You could simply write a list of ever possible game possible (It's not as grandiose as it sounds, since you can rotate the board during each check to cut the number down to 1/4 of the actual possible games) and give the computer instructions on how to play based on each board. middle is worth the most, then the corners, then the edges), and have the AI pick from the highest value available squares.Ī variation on this is to save each game played, and change values of squares based on previous games and their results. You could also give each square a specific value (ie. You could even build an entire instruction set that makes the computer unbeatable by setting up a few rules in a specific order,ģ. One of the easiest is of course just having it choose a random position on the board.įrom there you could work your way up to something like andywestken suggested and use rules, for example if the computer could win the game on its turn, it will always take the winning position instead of moving completely randomly, or you could have it block your possible wins. Do you understand pointer derferencing? (like *b) If not yet, don't use it (yet)!įor your AI question, there are many ways to do it, with varying difficulties. As drunken meerkat said, you need a call to srand(time(0)) at the start of your program. Use commenting to block out most of you code, getting each bit to work in turn (depedencies allowing). sort out your board drawing logic : what shape is the board? ensure all your array are big enough! e.g. (Look up how to use command line parameters) Then maybe you could modify your code so the two AIs can play each other! Once you have a version which can complete a game, even if it looses, freeze it. Play the game yourself, or against a friend, and record the moves. It can't call check() as the PC can't use the keyboard! I would first get your random code to work. Think of how few tests you need for each row! You need to scan each row and col, and then the diags! If it was just int i, turn() would update its own copy of i and the new result would not get back to main.Ģ. Without the
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |