Git Product home page Git Product logo

go-tic-tac-toe's Introduction

Tic-Tac-Toe

This is a Command Line Interface Tic Tac Toe game implemented in Go, where the player can play against an artificial intelligence.

Installation & Usage

To run this program, you need to have the Go compiler installed on your system. You can follow the installation instructions on Go's website

To get started with the program, you need to first clone or download the repository. You can do this by clicking on the "Code" button at the top of the repository page and selecting "Download ZIP" to download a compressed file of the repository, or copy the repository URL and run the following command in your terminal:

git clone https://github.com/beatrizhub/go-tic-tac-toe

Once you have the compiler installed and cloned this repository, move into the program's directory and run it using one of the following command:

go run .

Gameplay

When the game starts, enter the row and column (1, 2, or 3) of the cell where you want to place your marker separated by a single space (e.g. 1 3). After your move, the AI will make its move and the game board will be displayed.

The game continues until there's a tie or either the player or the AI wins.

Algorithm

The AI in this program uses uses a simple strategy to select its moves. It first checks for any winning move by iterating through all the empty cells on the board and placing the computer's symbol in each one. If a move results in a win, the function immediately returns and the move is made.

If there is no winning move available, the function checks for a blocking move. It iterates through all the empty cells on the board again and places the player's symbol in each one. If a move results in blocking the player from winning, the computer places its symbol in that cell and returns, making the move.

If neither a winning nor a blocking move is available, the function makes a random move. It generates a random row and column until an empty cell is found, and then places the computer's symbol in that cell.

Overall, this function prioritizes winning over blocking the player's moves, and random moves are made only when no winning or blocking moves are available.

License

This program is licensed under the MIT License. Feel free to use and modify this program for your own purposes.

go-tic-tac-toe's People

Stargazers

LifeCANvs avatar Humberto Dias avatar Clayton Kehoe avatar

Watchers

bea 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.