Skip to content

TicTacToe game with computer autoplayer

Notifications You must be signed in to change notification settings

nmanumr/CSC103-game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tic Tac Toe

Tic Tac Toe game written in pure C with computer autoplayer support. Tested with gcc 8.3.0 on Ubuntu 18.10. This should work on all xterm terminals, but only tested on xtermjs, konsole, gnome-terminal.

Online Demo: https://repl.it/@nmanumr/Tic-Tac-Toe

Compiling & Running

# Compiling & running game
make run

# Compiling & running game for xterm
make run.xterm

Autoplay Algorithm

Currently this only works for 3x3 boards but little optimization can make it work for nxn boards also. There are two techinques we use depending on the situation.

  1. Corner First (when center is occupied by oponent)
  2. Side First (when center is occupied by computer)

Corner First

This techinques goes something like following:

  1. If player has only one missing in row, col or diagonal mark the missing one.
  2. Take center if possible
  3. Take opposite empty corner of your oppoennt if any
  4. Take any of the empty corner if any
  5. Take empty side if any

Side First

This techinques is also very similar to Corner First but with a little order shift.

  1. If player has only one missing in row, col or diagonal mark the missing one.
  2. Take center if possible
  3. Take empty side if any
  4. Take opposite empty corner of your oppoennt if any
  5. Take any of the empty corner if any

TODO

  • Refector code to seperate rendering, game and autoplayer logic from include/Game.h
  • Autoplayer support for nxn boards
  • (TBD) move to ncurses lib

ScreenShots

Board Size 5 Won Draw