Skip to content

Commit

Permalink
Make negamax friends to JS backend
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnAD committed May 30, 2018
1 parent 83ce7cd commit 3356de9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ echo "history: " & $history

For the content pulled by "import knights", see https://github.com/JohnAD/negamax/blob/master/examples/knights.nim

# Videos

The following two videos (to be watched in sequence), demonstrate how to use this library and the 'turn_based_game' library:

* Using "turn_based_game": https://www.youtube.com/watch?v=u6w8vT-oBjE
* Using "negamax": https://www.youtube.com/watch?v=op4Mcgszshk

# Credit

The code for this engine mimics that written in Python at the EasyAI library located at <https://github.com/Zulko/easyAI>. That library contains both the game rule engine (called TwoPlayerGame) as well as a variety of AI algorithms to play as game players, such as Negamax.
2 changes: 1 addition & 1 deletion negamax.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.0.1"
version = "0.0.2"
author = "John Dupuy"
description = "Negamax AI algorithm for turn based games"
license = "MIT"
Expand Down
6 changes: 5 additions & 1 deletion src/negamax.nim
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,14 @@ type
NegamaxPlayer* = ref object of Player
depth*: int


#
method get_move*(self: NegamaxPlayer, game: Game): string =
var new_game: Game
deepCopy(new_game, game)
when defined(js):
new_game = game
else:
deepCopy(new_game, game)
var choice = negamax(new_game, self.depth)
return choice

Expand Down

0 comments on commit 3356de9

Please sign in to comment.