Skip to content

Commit

Permalink
Clean up; use proper INF for alpha/beta
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnAD committed May 20, 2018
1 parent 9fc9bf4 commit 99faf50
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The bulk of the work is in making the game itself. See the _turn_based_game_ lib
* turn_based_game (repo): <https://github.com/JohnAD/turn_based_game>
* turn_based_game (docs): <https://github.com/JohnAD/turn_based_game/wiki>

Once made, simply import the negamax library and use a `NegamaxPlayer` instead of a normal `Player`. Include the `depth` of the search as an object parameter. The depth is measured in **plies**. One **ply** is a single turn. So, a round of play between two players is two plies.
Once made, simply import the negamax library and use a `NegamaxPlayer` instead of a normal `Player`. Include the `depth` of the search as an object parameter. The depth is measured in **plies**. One **ply** is a single play. So, one full round of play between two players is two plies.

The Negamax AI specifically requires that the

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import turn_based_game
import knights
import "../src/negamax"
import negamax
import strutils

const
Expand Down
12 changes: 0 additions & 12 deletions examples/knights_with_human.nim

This file was deleted.

9 changes: 2 additions & 7 deletions src/negamax.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import tables
import turn_based_game


let INF = 999999.9
let NEGINF = -999999.9

proc negamax_core(game: var Game, ai_choice: var string, depth: int, orig_depth: int, alpha_in: float, beta_in: float): float =

var
Expand Down Expand Up @@ -36,7 +33,7 @@ proc negamax_core(game: var Game, ai_choice: var string, depth: int, orig_depth:
# set up defaults/fall-throughs
#
var best_move = possible_moves[0]
var best_value = NEGINF
var best_value = -INF

for move in possible_moves:

Expand Down Expand Up @@ -81,7 +78,7 @@ proc negamax*(game: var Game, depth: int): string =
ai_choice: string
possible_moves: seq[string] = @[]

alpha = NEGINF
alpha = -INF
beta = INF


Expand All @@ -107,8 +104,6 @@ type
NegamaxPlayer* = ref object of Player
depth*: int


# TODO: verify that default depth=0 works-ish
#
method get_move*(self: NegamaxPlayer, game: Game): string =
var new_game: Game
Expand Down

0 comments on commit 99faf50

Please sign in to comment.