https://github.com/zsarge/tic-tac-toe-hs
just a basic project to stay fresh in Haskell
https://github.com/zsarge/tic-tac-toe-hs
Last synced: 10 months ago
JSON representation
just a basic project to stay fresh in Haskell
- Host: GitHub
- URL: https://github.com/zsarge/tic-tac-toe-hs
- Owner: zsarge
- License: mit
- Created: 2024-12-27T07:20:11.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-27T21:14:32.000Z (over 1 year ago)
- Last Synced: 2025-05-21T23:09:10.625Z (about 1 year ago)
- Language: Haskell
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# tic-tac-toe-hs
This is just a basic project to stay fresh in Haskell.
Tic-Tac-Toe was a good project to practice using Monads like `IO` and `Maybe`.
All the code is in [`Main.hs`](./app/Main.hs).
## Example Inputs
All inputs were run with `cabal run`.
1,2,3,4,5,6,7
```
1 | 2 | 3
---+---+---
4 | 5 | 6
---+---+---
7 | 8 | 9
Player X's turn!
What index do you want to move to?
1
You selected 1
X | 2 | 3
---+---+---
4 | 5 | 6
---+---+---
7 | 8 | 9
Player O's turn!
What index do you want to move to?
2
You selected 2
X | O | 3
---+---+---
4 | 5 | 6
---+---+---
7 | 8 | 9
Player X's turn!
What index do you want to move to?
3
You selected 3
X | O | X
---+---+---
4 | 5 | 6
---+---+---
7 | 8 | 9
Player O's turn!
What index do you want to move to?
4
You selected 4
X | O | X
---+---+---
O | 5 | 6
---+---+---
7 | 8 | 9
Player X's turn!
What index do you want to move to?
5
You selected 5
X | O | X
---+---+---
O | X | 6
---+---+---
7 | 8 | 9
Player O's turn!
What index do you want to move to?
6
You selected 6
X | O | X
---+---+---
O | X | O
---+---+---
7 | 8 | 9
Player X's turn!
What index do you want to move to?
7
You selected 7
X | O | X
---+---+---
O | X | O
---+---+---
X | 8 | 9
X wins!
```
1,4,2,5,3
```
1 | 2 | 3
---+---+---
4 | 5 | 6
---+---+---
7 | 8 | 9
Player X's turn!
What index do you want to move to?
1
You selected 1
X | 2 | 3
---+---+---
4 | 5 | 6
---+---+---
7 | 8 | 9
Player O's turn!
What index do you want to move to?
4
You selected 4
X | 2 | 3
---+---+---
O | 5 | 6
---+---+---
7 | 8 | 9
Player X's turn!
What index do you want to move to?
2
You selected 2
X | X | 3
---+---+---
O | 5 | 6
---+---+---
7 | 8 | 9
Player O's turn!
What index do you want to move to?
5
You selected 5
X | X | 3
---+---+---
O | O | 6
---+---+---
7 | 8 | 9
Player X's turn!
What index do you want to move to?
3
You selected 3
X | X | X
---+---+---
O | O | 6
---+---+---
7 | 8 | 9
X wins!
```
3,2,6,5,8,9,1,4,7
```
1 | 2 | 3
---+---+---
4 | 5 | 6
---+---+---
7 | 8 | 9
Player X's turn!
What index do you want to move to?
3
You selected 3
1 | 2 | X
---+---+---
4 | 5 | 6
---+---+---
7 | 8 | 9
Player O's turn!
What index do you want to move to?
2
You selected 2
1 | O | X
---+---+---
4 | 5 | 6
---+---+---
7 | 8 | 9
Player X's turn!
What index do you want to move to?
6
You selected 6
1 | O | X
---+---+---
4 | 5 | X
---+---+---
7 | 8 | 9
Player O's turn!
What index do you want to move to?
5
You selected 5
1 | O | X
---+---+---
4 | O | X
---+---+---
7 | 8 | 9
Player X's turn!
What index do you want to move to?
8
You selected 8
1 | O | X
---+---+---
4 | O | X
---+---+---
7 | X | 9
Player O's turn!
What index do you want to move to?
9
You selected 9
1 | O | X
---+---+---
4 | O | X
---+---+---
7 | X | O
Player X's turn!
What index do you want to move to?
1
You selected 1
X | O | X
---+---+---
4 | O | X
---+---+---
7 | X | O
Player O's turn!
What index do you want to move to?
4
You selected 4
X | O | X
---+---+---
O | O | X
---+---+---
7 | X | O
Player X's turn!
What index do you want to move to?
7
You selected 7
X | O | X
---+---+---
O | O | X
---+---+---
X | X | O
Game Over!
```