Skip to content

Commit

Permalink
added test and more ss
Browse files Browse the repository at this point in the history
  • Loading branch information
Vivek Dagar committed Apr 5, 2024
1 parent c1d9b94 commit 9dafcb0
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 32 deletions.
Empty file removed CODE_OF_CONDUCT.md
Empty file.
Empty file removed CONTRIBUTING.md
Empty file.
86 changes: 54 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,29 @@
</p>
</p>

![Issues](https://img.shields.io/github/issues/vivekkdagar/TicTacAI) ![License](https://img.shields.io/github/license/vivekkdagar/TicTacAI)
![Issues](https://img.shields.io/github/issues/vivekkdagar/TicTacAI) &nbsp; ![License](https://img.shields.io/github/license/vivekkdagar/TicTacAI) &nbsp; ![Python 3 Logo](https://img.shields.io/badge/-Python%203-3776AB?logo=python&logoColor=white) &nbsp; ![Click Logo](https://img.shields.io/badge/-Click-3776AB?logo=python&logoColor=white) &nbsp; ![Tabulate Logo](https://img.shields.io/badge/-Tabulate-3776AB?logo=python&logoColor=white) &nbsp; ![PrettyTable Logo](https://img.shields.io/badge/-PrettyTable-3776AB?logo=python&logoColor=white)


![Workflow Status](https://github.com/vivekkdagar/TicTacAI/actions/workflows/python-publish.yml/badge.svg)&emsp;
![Workflow Status](https://github.com/vivekkdagar/TicTacAI/actions/workflows/python-package.yml/badge.svg)&emsp;




## Table Of Contents

* [About the Project](#about-the-project)
* [Built With](#built-with)
* [Technical Implementation Highlights](#technical-implementation-highlights)
* [Getting Started](#getting-started)
* [Prerequisites](#prerequisites)
* [Installation](#installation)
* [Usage](#usage)
* [Contributing](#contributing)
* [License](#license)
* [Authors](#authors)
* [Acknowledgements](#acknowledgements)

## About The Project

![Screen Shot](https://github.com/vivekkdagar/TicTacAI/blob/main/assets/screenshot.png)
![Screen Shot](https://github.com/vivekkdagar/TicTacAI/blob/main/screenshots![img.png](img.png)/screenshot.png)

## Gameplay

Expand Down Expand Up @@ -59,69 +64,86 @@

## Getting Started

This is an example of how you may give instructions on setting up your project locally.
To get a local copy up and running follow these simple example steps.
To get started with this project, you have two options:

1. **Using PyPI**: Install the package directly from the Python Package Index (PyPI) using pip. PyPI always provides stable and tested versions.
2. **Local Build**: Build and install the package locally. Local builds may contain the newest features but could also be unstable and potentially buggy.

Choose the method that best suits your needs and follow the respective instructions below.

### Prerequisites

There are 2 ways of setting up this project
When using PyPI, pip automatically handles dependencies, ensuring that all required packages are installed.

* npm
For local builds, install dependencies with:

```sh
npm install npm@latest -g
pip install -r requirements.txt
```

### Installation

1. Get a free API Key at [https://example.com](https://example.com)
#### When using Pypi
```commandline
pip install tictacai
```

#### Building locally

2. Clone the repo
1. Clone the repo

```sh
git clone https://github.com/your_username_/Project-Name.git
git clone https://github.com/vivekkdagar/TicTacAI/tree/main
```

3. Install NPM packages
2. Go to the project directory

```sh
npm install
cd tictacai
```

4. Enter your API in `config.js`
3. Build the package

```JS
const API_KEY = 'ENTER YOUR API';
python3 -m build
```

## Usage
4. Install the package

Use this space to show useful examples of how a project can be used. Additional screenshots, code examples and demos work well in this space. You may also link to more resources.
```commandline
cd dist
pip install *gz
```

_For more examples, please refer to the [Documentation](https://example.com)_
## Usage

## Contributing
It provides the following command-line interface:

**1. Play against Human**
```commandline
tictacai human
```
This command starts a game where two humans can play against each other.

**2. Play against AI**
```commandline
tictacai ai
```
This command starts a game where a human can play against the AI.

### Creating A Pull Request
3. Display Scores
```commandline
tictacai scores
```
This command displays statistics about the game, such as total matches played, player wins, draws, etc.

1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request
**One thing to note** is scores are stored in a JSON file in Document/TicTacAI so if it is deleted, scores are reset to 0.

## License

Distributed under the MIT License. See [LICENSE](https://github.com/vivekkdagar/TicTacAI/blob/main/LICENSE.md) for more information.

## Authors

* **Vivek Dagar** - *Comp Sci Student* - [Vivek Dagar](https://github.com/ShaanCoding/) - *Built ReadME Template*

## Acknowledgements

* [README Generator](https://readme.shaankhan.dev/)
* [ImgShields](https://shields.io/)
* []()
Binary file added img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/game_completed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/game_started.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/scores.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added screenshots/starting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions tests/test_game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import unittest
from tictacai.game import Game
from tictacai.game import empty_cells, wins


class TestGame(unittest.TestCase):
def setUp(self):
self.game = Game()

def test_wins(self):
# Test wins function
state = [['X', ' ', ' '], ['O', 'X', 'O'], [' ', ' ', 'X']]
self.assertTrue(wins(state, 'X'))
self.assertFalse(wins(state, 'O'))

def test_empty_cells(self):
# Test empty_cells function
state = [['X', ' ', ' '], ['O', 'X', 'O'], [' ', ' ', 'X']]
self.assertEqual(empty_cells(state), [[0, 1], [0, 2], [2, 0], [2, 1]])

def test_evaluate(self):
# Test evaluate function
state1 = [['X', 'X', 'X'], [' ', 'O', 'O'], [' ', ' ', ' ']]
state2 = [['O', 'O', 'O'], [' ', 'X', 'X'], [' ', ' ', ' ']]
state3 = [['X', 'O', 'X'], [' ', 'O', 'X'], [' ', 'X', 'O']]
self.assertEqual(self.game.evaluate(state1), -1) # X wins
self.assertEqual(self.game.evaluate(state2), 1) # O winner
self.assertEqual(self.game.evaluate(state3), 0) # No winner

def test_game_over(self):
# Test game_over function
state1 = [['X', 'X', 'X'], [' ', 'O', 'O'], [' ', ' ', ' ']]
state2 = [['O', 'O', ' '], ['X', 'X', 'X'], [' ', ' ', ' ']]
state3 = [['X', 'O', 'X'], [' ', 'O', 'X'], [' ', 'X', 'O']]
self.assertTrue(self.game.game_over(state1)) # X wins
self.assertTrue(self.game.game_over(state2)) # X wins
self.assertFalse(self.game.game_over(state3)) # No winner


if __name__ == '__main__':
unittest.main()

0 comments on commit 9dafcb0

Please sign in to comment.