Code Monkey home page Code Monkey logo

tic-tac-toe-game's Introduction

Play tic-tac-toe game against computer.

Tic-tac-toe or noughts and crosses is a paper-and-pencil game for two players who take turns marking the spaces in a three-by-three grid with X or O. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row is the winner.

The board should be implemented using nested lists.
This is an example of the board:

 column   
 1  2  3   
[ ][ ][ ]  row 1   
[ ][ ][ ]  row 2   
[ ][ ][ ]  row 3  
  • To create a movement you need to type the first value for the row(1-3) then click Enter and then type the value for the column(1-3) and click Enter.
  • The program moves after you and your moves and the program’s moves are immediately displayed.
Left 9 moves
Select a row (1-3)2
Select a column (1-3)3
Your move:
[ ][ ][ ]
[ ][ ][X]
[ ][ ][ ]
Program move:
[ ][ ][0]
[ ][ ][X]
[ ][ ][ ]
Left 7 moves
Select a row (1-3)

Function testForFreeCell() display how many free moves are left. If there are no free cells, it will be a draw.

def testForFreeCell():
  
    empty=0
    for i in range(0,3):
        for j in range(0,3):
            if field[i][j]==' ':
                empty+=1
    return empty
while True:
    if testForFreeCell()==0:
        print("Draw")
        break

Game tactics of the program "Random selection", this leaves room for improvement in program tactics.

tic-tac-toe-game's People

Contributors

nathkoch avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.