Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4f91069

Browse files
randomly shuffling the move list to make games more exciting
1 parent e28c8d5 commit 4f91069

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

‎Engine.py‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def movable_tigers(self):
156156

157157
return sum(int(self._movable(t)) for t in self.board.tigerPos)
158158

159-
def generate_move_list(self):
159+
def generate_move_list(self, rdm=True):
160160
"""
161161
Generate a list of all moves for the board and turn
162162
"""
@@ -172,12 +172,26 @@ def generate_move_list(self):
172172
else:
173173
move_list.extend(self._movements())
174174

175+
# randomly shuffling the move list
176+
# so the ai doesn't make the same move every time
177+
178+
if rdm:
179+
random.shuffle(move_list)
175180
# turn = Tiger
176181
else:
177182
# captures
178-
move_list.extend(self._captures())
179-
# moves
180-
move_list.extend(self._movements())
183+
# captures are kept before movements
184+
# to improve the efficiency of ab pruning
185+
moves = self._captures()
186+
if rdm:
187+
random.shuffle(moves)
188+
move_list.extend(moves)
189+
190+
# movements
191+
moves = self._movements()
192+
if rdm:
193+
random.shuffle(moves)
194+
move_list.extend(moves)
181195

182196
return move_list
183197

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /