Skip to content

Commit

Permalink
checks are considered during max_deep_captures phase
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugen Kostieiev committed Jan 12, 2017
1 parent 8c546ed commit 9df0ec3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
2 changes: 1 addition & 1 deletion advicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def run_advicer(mode, max_deep, lines, board, board_hashes):
print 'Run advicer...'
max_deep_captures = 1
max_deep_captures = 3

# a = time.time()
# pre_analysis = run_analyzer(
Expand Down
39 changes: 25 additions & 14 deletions analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ def dfs(self, board, alpha, beta, analyze_launch_time, moves_to_consider=None,
`moves_to_consider` - moves to consider, if None than all valid moves are considered
only if deep < max_deep
deep < max_deep
- all moves
max_deep <= deep < max_deep + max_deep_captures
- captures (if check then all moves)
max_deep + max_deep_captures <= deep < max_deep + max_deep_captures + max_deep_one_capture
- one capture
'''
if time.time() - analyze_launch_time > self.max_time:
# If alpha or beta is determined here, than there is calculated one variant already
Expand All @@ -226,21 +233,25 @@ def dfs(self, board, alpha, beta, analyze_launch_time, moves_to_consider=None,
is_any_move = False

if deep >= self.max_deep:
result = self.board_evaluation(board)
is_any_move = True

if len(result) == lines:
if move_color == WHITE:
alpha = max(alpha, result[-1]['evaluation'])
else:
beta = min(beta, result[-1]['evaluation'])

if (alpha >= beta or
deep == self.max_deep + self.max_deep_captures + self.max_deep_one_capture):
# No moves should be considered
moves = []
if (deep < self.max_deep + self.max_deep_captures
and board.is_check(opposite=True)):
moves = board.get_board_moves(capture_sort_key=Board.sort_take_by_value)
else:
moves = board.get_board_captures(capture_sort_key=Board.sort_take_by_value)
result = self.board_evaluation(board)
is_any_move = True

if len(result) == lines:
if move_color == WHITE:
alpha = max(alpha, result[-1]['evaluation'])
else:
beta = min(beta, result[-1]['evaluation'])

if (alpha >= beta or
deep == self.max_deep + self.max_deep_captures + self.max_deep_one_capture):
# No moves should be considered
moves = []
else:
moves = board.get_board_captures(capture_sort_key=Board.sort_take_by_value)
else:
moves = board.get_board_moves(
capture_sort_key=Board.sort_take_by_value) if moves_to_consider is None else moves_to_consider
Expand Down
8 changes: 5 additions & 3 deletions board.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ def evaluation_params(self):
- space
- king safety
'''
SPACE_MAX = 3

material = [0, 0]
development = [0, 0]
center = [0, 0]
Expand All @@ -96,11 +94,15 @@ def evaluation_params(self):
if piece == 'pawn':
if 3 <= position[0] <= 4:
if ind == 0:
if position[1] == 3:
if position[1] == 4:
center[ind] += 7
elif position[1] == 3:
center[ind] += 15
elif position[1] == 2:
center[ind] += 7
else:
if position[1] == 3:
center[ind] += 7
if position[1] == 4:
center[ind] += 15
elif position[1] == 5:
Expand Down
4 changes: 2 additions & 2 deletions board_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def get_settings(mode):
'moved_black_board_cell': (218 / 255.0, 195 / 255.0, 75 / 255.0),
'letter': (152 / 255.0, 150 / 255.0, 149 / 255.0)
}
cell_size = 74
cell_size = 68
pixels = {
'pawn': {
'white': [((43, 58), 'black_piece'), ((79, 91), ('white_piece'))],
Expand All @@ -115,7 +115,7 @@ def get_settings(mode):
'black': [((56, 79), 'white_piece'), ((110, 63), ('black_piece'))],
}
}
pixels = {"king": {"white": [[[62, 101], "white_piece"], [[74, 93], "black_piece"]], "black": [[[44, 101], "black_piece"], [[25, 73], "white_piece"]]}, "rook": {"white": [[[86, 106], "black_piece"], [[75, 35], "white_piece"]], "black": [[[35, 33], "black_piece"], [[104, 115], "black_piece"]]}, "pawn": {"white": [[[50, 102], "white_piece"], [[48, 106], "white_piece"]], "black": [[[97, 113], "black_piece"], [[43, 122], "black_piece"]]}, "knight": {"white": [[[102, 91], "white_piece"], [[41, 54], "black_piece"]], "black": [[[90, 124], "black_piece"], [[53, 33], "black_piece"]]}, "queen": {"white": [[[55, 125], "white_piece"], [[105, 30], "black_piece"]], "black": [[[127, 43], "black_piece"], [[72, 128], "black_piece"]]}, "bishop": {"white": [[[66, 71], "white_piece"], [[48, 105], "black_piece"]], "black": [[[86, 84], "white_piece"], [[99, 69], "black_piece"]]}}
pixels = {"king": {"white": [[[27, 75], "white_piece"], [[80, 108], "black_piece"]], "black": [[[42, 60], "black_piece"], [[61, 75], "white_piece"]]}, "rook": {"white": [[[77, 75], "white_piece"], [[67, 42], "black_piece"]], "black": [[[86, 43], "white_piece"], [[52, 94], "black_piece"]]}, "pawn": {"white": [[[65, 77], "white_piece"], [[85, 112], "white_piece"]], "black": [[[73, 108], "black_piece"], [[44, 102], "black_piece"]]}, "knight": {"white": [[[82, 101], "white_piece"], [[46, 115], "black_piece"]], "black": [[[30, 44], "black_piece"], [[93, 100], "black_piece"]]}, "queen": {"white": [[[49, 84], "white_piece"], [[72, 51], "black_piece"]], "black": [[[111, 32], "black_piece"], [[68, 77], "black_piece"]]}, "bishop": {"white": [[[45, 57], "white_piece"], [[52, 91], "black_piece"]], "black": [[[22, 112], "black_piece"], [[42, 50], "black_piece"]]}}
white_letter_count = 112
black_letter_count = 60

Expand Down

0 comments on commit 9df0ec3

Please sign in to comment.