Thursday, June 23, 2011

Mini project Tic Tac Toe game source code in C programming

The mini project Tic Tac Toe game in C programming is a console application created without graphics. We draw the game using only asterisks, X, and O characters. The user can choose to play first or second, and the opponent is a computer algorithm. I haven't used a complex AI algorithm to implement the computer player. Implementing an AI algorithm would require creating a complex data structure, which is beyond the scope of this article. Tic Tac Toe is a relatively simple game to play and understand. Since it has a fixed number of small sets of game moves, I have formulated a series of steps to choose the best move for the computer player.

The best move for computer player is choose based on following principle.
  1. At first, always check and choose wining move.
  2. Second, if opponent is wining choose draw move.
  3. Third, choose best next move from series of pre-define steps. 
In this article, I will explain the following items:
  • Algorithm of computer player
  • Flowchart of the game
  • Data Structure
  • Technique to switch the players, and check winner
I have explained the game in the following two articles:






Also, download the final version of game Download from GitHub.


44 comments:

  1. Replies
    1. Mrs. Kavin DickupmypussyJanuary 31, 2017 at 9:38 PM

      I wish i could see your site. if you know what i mean.
      ;) ;)

      Delete
  2. Replies
    1. Janu meri jaan, meh tere kurbaan.
      Janu meri jaa, meh tere kurbaan, meh tera tuh meri jaani saara hindustan.
      Meh tera tuh meri jane sara hindustan.
      <3 <3

      Delete
  3. Ihen i copy and paste the code it says:
    '::main' must return 'int'|
    In function 'int posswin(int)':|
    warning: unused variable 'pos'|
    ||=== Build finished: 1 errors, 1 warnings ===|

    ReplyDelete
    Replies
    1. instead of "main" try using "int"...i had that same error when i created a Tic Tac Toe for windows Console...

      hope it works :D

      Delete
    2. http://codereview.stackexchange.com/questions/41304/4%C3%974-tic-tac-toe-in-c
      dis s much better just change 4 to 3 and 16 to 9
      alok

      Delete
  4. hey can u help me wid the modification of the code??
    *I need to add a scoreboard that records the score of the computer and the player.

    Please mail me at adarsh2811@gmail.com

    ReplyDelete
  5. hey..do u have a simple code mini project like the sale program?
    tq..xD

    ReplyDelete
  6. what is the function of global variable (coord)
    and function "SetConsoleCursorPosition"........???????

    ReplyDelete
    Replies
    1. coord is a structure. SetConsoleCursorPosition set the cursor on the screen.

      Delete
    2. ok...but can't we use function "gotoxy()" instead of using SetConsoleCursorPosition .....?

      Delete
    3. gotoxy() in not builtin function, you can use SetConsoleCursorPosition instead of gotoxy() but before it you have to assign the Coord.x and Coord.y

      Delete
    4. ok :)
      thanx alot for helping me :)

      Delete
  7. I want to discuss it in detail....will you help me..?

    ReplyDelete
  8. Muhammad Wajeeh: Thanks yar. I need this code very very badly.
    Thank You Very Much

    ReplyDelete
  9. i converted it to C++ but there is some problem with the draw_board(), it enters into an infinite loop i suppose

    ReplyDelete
  10. I tried it out in linux platform and it gives me an error message as windows.h not found. Can I run this program only in turbo C++?

    ReplyDelete
    Replies
    1. Sorry you can't run it in linux platform.

      Delete
    2. i need help in linux .. will you help me @Shrivalli

      Delete
  11. sir?? is it for Visual C++? please reply me at my email add! chentzshockwaves@gmail.com thank you so much sir! its for our project.. :D

    ReplyDelete
  12. thic progrm can we run only in turbo c++ ? can i run it in turbo c?? because when i run the program it say diclaration error the couse are "COORD coord={0,0};// this global variabal " and "#includewindow.h? pless help mee!!

    ReplyDelete
  13. This program run in Code::Blocks IDE with MinGW compiler so it is better to download code::blocks and run it.

    ReplyDelete
  14. It doesn't work. Here's the error: http://bpaste.net/show/C9HiO73ed6iHYoPLHKRL/

    ReplyDelete
  15. hey man can i get some help.. email me at hackergeorge8@hotmail.com

    ReplyDelete
  16. is this program can run on turbo c ???..

    ReplyDelete
  17. Helo i am new to programming......
    can i get the explanition of ds source code....

    ReplyDelete
  18. sir i want know the working process of this code .... can u help me .......

    ReplyDelete
  19. this program is not running in turboo c. so plz help me to run this program

    ReplyDelete
  20. this code is working if you change line 30 "void" to "int".

    ReplyDelete
  21. your code does not even compile on ideone...why do you write such crappy and useless codes..go and get a life instead...
    no indentation - nothing!!!
    You look like a noob...learn some decent 'hello world' codes first instead of practicing gtk...

    ReplyDelete
  22. hey headfucked asshole ........ first compile the code asshole.....go play tic tac toe. or fuck tac toe.

    ReplyDelete
  23. i need the report for this project

    ReplyDelete
  24. I get an error:
    [Error] '::main' must return 'int'
    please help me

    ReplyDelete
  25. Thank you so much,
    This is the only working TIC TAC TOE code online with least possible fixes.
    Just changed the "void main()" to "int main" and all works well.
    You have my regards
    Thank you.

    ReplyDelete
  26. I Need function for windows.h for this tic tac toe can anyone help me. please thepapex5360@gmail.com

    ReplyDelete
  27. IF ANYBODY HAVE MINI PROJECTS ON C AND C++ PLS SEND THIS MAIL
    muthyala.nagaraju7@gmail.com

    ReplyDelete
  28. I want playe against other player..what i must change?

    ReplyDelete
  29. i have this game in simple code made by me this code is very difficult i made it very clear and easy.......

    ReplyDelete
  30. Can i get the explanation for this source code?

    ReplyDelete