11#![ allow( unused_must_use) ]
2- use crate :: piece_move:: PieceMove ;
3- use crate :: { BoardMap , PieceColor } ;
2+ use crate :: piece_color:: PieceColor ;
3+ use crate :: position_move:: PositionMove ;
4+ use crate :: BoardMap ;
45use rand:: Rng ;
56
67#[ derive( Default , Clone ) ]
@@ -10,17 +11,17 @@ impl ChessEngine {
1011 const MIN : f32 = -1000. ;
1112 const MAX : f32 = 1000. ;
1213
13- pub fn find_best_move_minimax_ab ( & mut self , board : BoardMap , depth : usize ) -> PieceMove {
14+ pub fn find_best_move_minimax_ab ( & mut self , board : BoardMap , depth : usize ) -> PositionMove {
1415 let mut best_value = Self :: MIN ;
1516 let mut best_moves = vec ! [ ] ;
1617 for from in board. get_active_pieces ( ) {
1718 let moves = board. gen_legal_positions ( from) ;
1819 for to in moves {
19- let piece_move = PieceMove :: new ( from, to) ;
20+ let piece_move = PositionMove :: new ( from, to) ;
2021 let piece_value = board. get_piece ( from) . 0 ;
2122 let mut temp_board = board;
2223
23- temp_board. move_turn ( piece_move) ;
24+ temp_board. single_move_turn ( piece_move) ;
2425 let move_value =
2526 self . ab_max ( depth, temp_board, ChessEngine :: MIN , ChessEngine :: MAX , true ) ;
2627 temp_board. undo_move ( piece_move, piece_value) ;
@@ -49,17 +50,17 @@ impl ChessEngine {
4950 best_moves[ index]
5051 }
5152
52- pub fn find_best_move_negamax ( & mut self , board : BoardMap , depth : usize ) -> PieceMove {
53+ pub fn find_best_move_negamax ( & mut self , board : BoardMap , depth : usize ) -> PositionMove {
5354 let mut best_value = Self :: MIN ;
5455 let mut best_moves = vec ! [ ] ;
5556 for from in board. get_active_pieces ( ) {
5657 let moves = board. gen_legal_positions ( from) ;
5758 for to in moves {
58- let piece_move = PieceMove :: new ( from, to) ;
59+ let piece_move = PositionMove :: new ( from, to) ;
5960 let piece_value = board. get_piece ( from) . 0 ;
6061
6162 let mut temp_board = board;
62- temp_board. move_turn ( piece_move) ;
63+ temp_board. single_move_turn ( piece_move) ;
6364 let move_value = self . nega_max ( temp_board, depth) ;
6465 temp_board. undo_move ( piece_move, piece_value) ;
6566
@@ -96,7 +97,7 @@ impl ChessEngine {
9697 mut beta : f32 ,
9798 is_maximizing_player : bool ,
9899 ) -> f32 {
99- return if is_maximizing_player {
100+ if is_maximizing_player {
100101 // AB MAX
101102 if depth == 0 {
102103 return self . evaluate ( board) ;
@@ -108,7 +109,7 @@ impl ChessEngine {
108109
109110 let piece_value = board. get_piece ( piece_move. from ) . 0 ;
110111
111- temp_board. move_turn ( * piece_move) ;
112+ temp_board. single_move_turn ( * piece_move) ;
112113 let score = self . ab_max ( depth - 1 , temp_board, alpha, beta, !is_maximizing_player) ;
113114 temp_board. undo_move ( * piece_move, piece_value) ;
114115
@@ -132,7 +133,7 @@ impl ChessEngine {
132133
133134 let piece_value = board. get_piece ( piece_move. from ) . 0 ;
134135
135- temp_board. move_turn ( * piece_move) ;
136+ temp_board. single_move_turn ( * piece_move) ;
136137 let score = self . ab_max ( depth - 1 , temp_board, alpha, beta, !is_maximizing_player) ;
137138 temp_board. undo_move ( * piece_move, piece_value) ;
138139
@@ -144,7 +145,7 @@ impl ChessEngine {
144145 }
145146 }
146147 beta
147- } ;
148+ }
148149 }
149150
150151 fn nega_max ( & mut self , board : BoardMap , depth : usize ) -> f32 {
@@ -156,7 +157,7 @@ impl ChessEngine {
156157
157158 for piece_move in moves. iter ( ) {
158159 let mut temp_board = board;
159- temp_board. move_turn ( * piece_move) ;
160+ temp_board. single_move_turn ( * piece_move) ;
160161
161162 let value = -self . nega_max ( board, depth - 1 ) ;
162163 if value > max {
0 commit comments