Giter Club home page Giter Club logo

tictactoe's Introduction

Build Status CRAN Status

tictactoe

Play and learn Tic-Tac-Toe Game on R

installation and import

Install from CRAN

install.packages("tictactoe")

Or you may install the recent development version from github

devtools::install_github("kota7/tictactoe")

To use,

library(tictactoe)

Play a Game

You can play tic-tac-toe on R console.

ttt(ttt_human(), ttt_ai())

This would give you a prompt as below.

    A B C
   ------
 1| . . .
 2| . . .
 3| . . .

 Player 1 (no name) to play
choose move (e.g. A1) > 

Type a move, then the oppoenet will respond. To finish the game in the middle, type "exit".

The default AI player is very week (in fact, he plays randomly). To play against a more sophisticated player, set the level argument (from 0 (weekest) to 5 (strongest)).

ttt(ttt_human(), ttt_ai(level = 4))

You may play as the second mover by ttt(ttt_ai(), ttt_human()). You may watch games between AI players by ttt(ttt_ai(), ttt_ai()).

Simulation

To conduct a large scale simulation between AI players, use ttt_simulate function. The code below conducts 100 simulation games between random AIs. The result 0, 1, and 2 indicate draw, won by player 1, and won by player 2 respectively.

res <- ttt_simulate(ttt_ai(), ttt_ai(), N = 100, verbose = FALSE)
prop.table(table(res))
#> res
#>    0    1    2 
#> 0.13 0.57 0.30

Q-learning

Q-learning is implemented to train AI players. The code below trains a random AI through Q-learninig of 500 episodes.

p <- ttt_ai()
o <- ttt_qlearn(p, N = 500, verbose = FALSE)

Now this player is much stronger than the random player.

res <- ttt_simulate(ttt_ai(), p, N = 100, verbose = FALSE)
prop.table(table(res))
#> res
#>    0    1    2 
#> 0.15 0.25 0.60

References

  • Sutton, Richard S and Barto, Andrew G. Reinforcement Learning: An Introduction. The MIT Press (1998)

tictactoe's People

Contributors

kota7 avatar

Watchers

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