Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Board.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,24 @@ def generate_move_list(self, rdm=True):

return move_list

def _get_empty_positions(self):
return [i.get_index(i.coord) for i in self.points if i.state.name == 'E']

def _is_closed(self, position):

for i in self._move_connections[position]:
if self.points[i].state.name in {'T', 'E'}:
return False
return True

@property
def no_of_closed_spaces(self):
closed_spaces = 0
for i in self._get_empty_positions():
if self._is_closed(i):
closed_spaces += 1
return closed_spaces

def copy(self):
board = Board()
board.points = self.points
Expand Down
13 changes: 7 additions & 6 deletions Engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def evaluate(self, depth=0):
"""
winner = self.board.winner
if not winner:
return 30 * self.board.movable_tigers() + 70 * self.board.deadGoats - depth
return 300 * self.board.movable_tigers() + 700 * self.board.deadGoats\
- 100 * self.board.no_of_closed_spaces - depth

if winner == Board.Player.G:
return -Engine.INF
Expand All @@ -37,7 +38,7 @@ def minmax(self, is_max=True, depth=0, alpha=-INF, beta=INF):

# find the minimum attainable value for the minimizer
if not is_max:
value = self.INF
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why replace INF?

value = 100000000
for move in self.board.generate_move_list():
# first make the move
self.board.make_move(move)
Expand All @@ -48,7 +49,7 @@ def minmax(self, is_max=True, depth=0, alpha=-INF, beta=INF):
beta = min(beta, value_t)


if value_t <= value:
if value_t < value:
value = value_t
beta = min(beta, value)
if depth == 0:
Expand All @@ -64,15 +65,15 @@ def minmax(self, is_max=True, depth=0, alpha=-INF, beta=INF):

# find the maximum attainable value for the maximizer
else:
value = -self.INF
value = -100000000
for move in self.board.generate_move_list():
# first make the move
self.board.make_move(move)

# go deeper in the search tree recursively
value_t = self.minmax(False, depth + 1, alpha, beta)

if value_t >= value:
if value_t > value:
value = value_t
alpha = max(alpha, value)
if depth == 0:
Expand All @@ -83,7 +84,7 @@ def minmax(self, is_max=True, depth=0, alpha=-INF, beta=INF):
# then revert the move
self.board.revert_move(move)

if alpha > beta:
if alpha >= beta:
break

return value
Expand Down
14 changes: 8 additions & 6 deletions ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ def __init__(self, canvas, statustext):
self.cids = []
self.from_idx = None

self.tiger_radius = 7
self.goat_radius = 5
self.tiger_radius = 20
self.goat_radius = 20

self.board_grid_x = [10, 60, 110, 160, 210]
self.board_grid_y = [10, 60, 110, 160, 210]
self.board_rect = [1, 1, 221, 221]
self.board_grid_x = [30, 130, 230, 330, 430]
self.board_grid_y = [30, 130, 230, 330, 430]
self.board_rect = [2, 2, 462, 462]

self.game = None
self.win = ''
Expand Down Expand Up @@ -326,10 +326,12 @@ def rules():
tk = tkinter.Tk()
tk.title('BaghChal')

tk.resizable(0, 0)

frame = tkinter.Frame(tk)
frame.pack(fill=BOTH, expand=1)

canvas = tkinter.Canvas(frame, width=220, height=220)
canvas = tkinter.Canvas(frame, width=460, height=460)
canvas.pack(fill=BOTH, expand=1, side=TOP, padx=1, pady=1)

statustext = tkinter.StringVar()
Expand Down