Skip to content

Commit

Permalink
readme: add example code usage
Browse files Browse the repository at this point in the history
  • Loading branch information
gucio321 committed Apr 24, 2021
1 parent 62a5200 commit 2fb6c7f
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,43 @@ go get -d ./...
go run .
```

## Examples usage of ttggame/ttgpcplayer

This simple example should show, how to use an AI game engine:

```golang
package main

import (
"fmt"

"github.com/gucio321/tic-tac-go/ttggame/ttgboard"
"github.com/gucio321/tic-tac-go/ttggame/ttgpcplayer"
"github.com/gucio321/tic-tac-go/ttggame/ttgletter"
)

func main() {
// create board
width, height := 3, 3
chainLen := 3
board := ttgboard.NewBoard(width, height, chainLen)

// fill board
board.SetIndexState(0, ttgletter.LetterX)
board.SetIndexState(4, ttgletter.LetterO)
board.SetIndexState(8, ttgletter.LetterX)
board.SetIndexState(6, ttgletter.LetterX)

fmt.Println(board)

// make move using AI engine
i := ttgpcplayer.GetPCMove(board, ttgletter.LetterO)
board.SetIndexState(i, ttgletter.LetterO)

fmt.Println(board)
}
```

## Screenshots

![menu](docs/menu.png)
Expand Down

0 comments on commit 2fb6c7f

Please sign in to comment.