![]() ![]() ![]() It makes adding the braces have very little influence on code length. This puts two certain wins for X as shown in state 10 and 11, so no matter which move O picks in state 7, X will ultimately win. Different board sizes and computer strength Also called 'noughts and crosses'. That's one of the main reason I personally really like the "opening brace on the if line" coding convention. Play Tic-Tac-Toe Games Index Puzzle Games Elementary Games Number Games Strategy Games Tic-Tac-Toe Play Tic-Tac-Toe against another player or the computer. I find it just too easy to accidentally make a mistake when refactoring code that does not use braces for single-statement ifs. What would happen if you wanted to change the x and o to the upper-case letters? That refactor would require multiple changes around the code, and be error-prone. Most of your constants should de defined as global variables or defines. You should really consider changing that whole approach.Ī simple "enum and switch"-based state machine would work just as well, and be a lot more straightforward. Gotos make code really hard to follow, and difficult to refactor. Printf("\nPlease input where you want to place O: ") Ĭhecker = PositionCalculation(board, selection, 'o') Īvoid using goto unless absolutely necessary If (HorizontalCheck(board) = true || VerticalCheck(board) = true || DiagonalCheck(board) = true) Printf("Invalid input, please try again: ") Ĭhecker = PositionCalculation(board, selection, 'x') Initializing the Board void BoardInitializer(char board) Would appreciate if anyone could look through my tic tac toe code and what I possibly do to improve upon it. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |