Interview Solution

A programmer is a person who passes as an exacting expert on the basis of being able to turn out, after innumerable punching, an infinite series of incomprehensive answers calculated with micrometric precisions from vague assumptions based on debatable figures taken from inconclusive documents and carried out on instruments of problematical accuracy by persons of dubious reliability and questionable mentality for the avowed purpose of annoying and confounding a hopelessly defenseless department that was unfortunate enough to ask for the information in the first place. Grid newsmagazine

Tic Tac Toe

Language Java | Level Intermediate | Category Interview Problems | July 24, 2015 4:52 pm

Comments


Interview Problem

Tic-tac-toe is a game for two players, who take turns marking the spaces in a grid.
Tic Tac Toe is a game use to play by two players using 3x3 grid. The player who succeeds in placing three respective marks in a horizontal, vertical, or diagonal row wins the game.

  • The player is known as X and the Computer play is O.
  • Players alternate placing Xs and Os on the game board until either opponent has three in a row or all nine squares are filled.
  • User plays always first


Output

   					 
This is a tic-tac-toe game 
You are playing against the computer!
Enter 1-9 to indicate your move
 | | 
-----
 | | 
-----
 | | 
Your move
Please enter your move(0-9): 
6
 | | 
-----
 | | 
-----
X| | 
Computer move: 1
 |O| 
-----
 | | 
-----
X| | 
Your move
Please enter your move(0-9): 
7
 |O| 
-----
 | | 
-----
X|X| 
Computer move: 4
 |O| 
-----
 |O| 
-----
X|X| 
Your move
Please enter your move(0-9): 
8
 |O| 
-----
 |O| 
-----
X|X|X
You won!


				    

Comments



Please login to add comments.