Skip to content

Commit

Permalink
draw issue solved
Browse files Browse the repository at this point in the history
  • Loading branch information
4belito committed Feb 26, 2024
1 parent 61daee5 commit e8ca910
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 73 deletions.
Binary file modified __pycache__/connect4.cpython-311.pyc
Binary file not shown.
10 changes: 5 additions & 5 deletions connect4.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def reset_board(self):

def process_move(self, column, board):
is_valid = False
if isinstance(column, (int,np.int32)) and 0 <= column < self.cols:
if isinstance(column, (int,np.int32,np.int64)) and 0 <= column < self.cols:
n_spots=sum(board[:,column]==0)
if n_spots:
board[n_spots-1,column]=1
Expand Down Expand Up @@ -201,7 +201,7 @@ def play(self, player1, player2):
is_valid, p1_board = self.process_move(self.move, p1_board.copy())
except Exception as exc:
is_valid=False
print(f"Error {exc} have occurred with player {p1}:")
print(f"Error {exc} has occurred with player {p1}:")
if is_valid:
self._board = p1_board
moves.append(self.move)
Expand All @@ -216,7 +216,7 @@ def play(self, player1, player2):
winner, reason,self._board = p1, f'Connect {self.connect_number}!', board_end
break
if not np.sum(self._board==0):
winner, reason = None, 'drawn'
winner, reason = None, 'draw'
break

if timed_out == True:
Expand All @@ -232,7 +232,7 @@ def play(self, player1, player2):
is_valid, p2_board = self.process_move(self.move, p2_board.copy())
except Exception as exc:
is_valid=False
print(f"Error {exc} have occurred with player {p2}:")
print(f"Error {exc} has occurred with player {p2}:")
if is_valid:
self._board = p2_board * (-1)
moves.append(self.move)
Expand All @@ -247,7 +247,7 @@ def play(self, player1, player2):
winner, reason,self._board = p2, f'Connect {self.connect_number}!', board_end*(-1)
break
if not np.sum(self._board==0):
winner, reason = None, 'drawn'
winner, reason = None, 'draw'
break

if timed_out == True:
Expand Down
136 changes: 68 additions & 68 deletions play.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -25,7 +25,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -49,17 +49,17 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"p1 = 'dummies/Random'\n",
"p2 = 'SmartRandom'\n",
"p1 = 'dummies/DropLowest'\n",
"p2 = 'dummies/SmartRandom'\n",
"#p1='human' #(increase TIME MOVE if your brain goes slower than a computer)\n",
"#p2 = 'dummies/SmartRandom'\n",
"#p1 = 'players.dummies/SmartRandom'\n",
"#p2 = 'SmartRandom'\n",
"#p1 = 'dummies/Random'\n",
"#p2 = 'dummies/LazySmartRandom' \n",
"#p1 = 'dummies/DropLowest'"
"#p1 = 'players.dummies/SmartRandom'"
]
},
{
Expand All @@ -77,98 +77,98 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Playing dummies/Random against SmartRandom\n",
"Playing dummies/DropLowest against dummies/SmartRandom\n",
"Final Board: \n",
"[[ 0 0 0 0 0 -1 -1 0]\n",
" [ 0 0 0 0 0 -1 -1 0]\n",
" [ 0 0 0 0 0 -1 1 0]\n",
" [-1 1 1 -1 0 -1 1 0]\n",
" [ 1 -1 1 1 0 1 1 1]\n",
" [ 1 -1 -1 -1 0 -1 -1 1]\n",
" [-1 1 1 1 1 -1 -1 1]]\n",
"[[ 0 0 0 0 0 0 0 0]\n",
" [ 0 0 0 0 0 0 0 0]\n",
" [ 0 0 0 0 0 0 0 0]\n",
" [ 0 0 0 0 0 0 0 0]\n",
" [ 0 0 -1 -1 0 0 0 0]\n",
" [ 0 0 -1 -1 0 0 0 0]\n",
" [ 1 -1 2 2 2 2 2 0]]\n",
"Moves: \n",
"[1, 5, 2, 6, 4, 6, 3, 5, 5, 5, 6, 1, 7, 2, 7, 5, 6, 0, 0, 1, 1, 3, 3, 5, 2, 5, 0, 3, 7, 0, 6, 6, 2, 6]\n",
"Winner: SmartRandom\n",
"Reason: Invalid moves exceeded 0\n",
"[0, 1, 2, 2, 3, 3, 4, 2, 5, 3, 6]\n",
"Winner: dummies/DropLowest\n",
"Reason: Connect 5!\n",
"----------------------------------\n",
"dummies/Random victories: 0\n",
"SmartRandom victories: 1\n",
"daws: 0\n",
"dummies/DropLowest victories: 1\n",
"dummies/SmartRandom victories: 0\n",
"draws: 0\n",
"----------------------------------\n",
"Final Board: \n",
"[[ 0 0 0 1 0 0 0 0]\n",
" [ 0 1 0 -1 0 0 0 0]\n",
" [ 0 1 1 1 0 0 0 0]\n",
" [ 0 -1 -1 1 -1 -1 1 0]\n",
" [ 0 -1 -1 -1 1 1 1 0]\n",
" [-1 -1 -1 1 -1 -1 1 -1]\n",
" [-1 1 1 1 1 -1 1 -1]]\n",
"[[ 0 0 0 0 0 0 0 0]\n",
" [ 0 0 0 0 0 0 0 0]\n",
" [ 0 0 0 0 0 0 0 0]\n",
" [-1 0 -1 -1 0 0 0 0]\n",
" [ 2 2 2 2 2 0 -1 0]\n",
" [ 1 -1 1 -1 -1 1 -1 -1]\n",
" [ 1 -1 1 1 -1 1 1 -1]]\n",
"Moves: \n",
"[3, 5, 3, 0, 2, 2, 4, 3, 1, 5, 5, 4, 6, 1, 3, 2, 6, 0, 6, 7, 4, 1, 6, 1, 1, 4, 1, 7, 3, 2, 2, 3, 3, 5]\n",
"Winner: SmartRandom\n",
"Reason: Invalid moves exceeded 0\n",
"[0, 1, 2, 7, 3, 4, 5, 1, 6, 7, 0, 4, 2, 3, 5, 6, 0, 6, 1, 0, 2, 2, 3, 3, 4]\n",
"Winner: dummies/DropLowest\n",
"Reason: Connect 5!\n",
"----------------------------------\n",
"dummies/Random victories: 0\n",
"SmartRandom victories: 2\n",
"daws: 0\n",
"dummies/DropLowest victories: 2\n",
"dummies/SmartRandom victories: 0\n",
"draws: 0\n",
"----------------------------------\n",
"Final Board: \n",
"[[ 0 0 0 0 0 0 0 0]\n",
" [ 0 0 0 0 0 0 0 0]\n",
" [ 0 0 1 0 0 0 0 0]\n",
" [ 0 -1 -1 -1 0 0 0 -1]\n",
" [ 1 -1 1 1 -1 0 0 -1]\n",
" [ 1 -1 1 1 1 1 0 1]\n",
" [-2 -2 -2 1 1 1 -2 -2]]\n",
" [ 0 0 -2 0 0 0 0 0]\n",
" [ 0 0 -2 0 0 -1 0 0]\n",
" [ 1 -1 -2 1 0 -1 0 0]\n",
" [-1 1 -2 -1 1 -1 1 1]\n",
" [-1 1 -2 1 -1 1 1 -1]\n",
" [ 1 1 1 1 -1 1 1 -1]]\n",
"Moves: \n",
"[4, 1, 4, 7, 5, 2, 7, 7, 3, 0, 2, 4, 2, 1, 3, 1, 3, 2, 5, 7, 2, 1, 0, 3, 0, 6]\n",
"Winner: SmartRandom\n",
"[0, 4, 1, 0, 2, 0, 3, 2, 5, 7, 6, 2, 1, 7, 3, 4, 5, 5, 6, 3, 1, 2, 4, 2, 6, 1, 7, 5, 0, 5, 3, 2]\n",
"Winner: dummies/SmartRandom\n",
"Reason: Connect 5!\n",
"----------------------------------\n",
"dummies/Random victories: 0\n",
"SmartRandom victories: 3\n",
"daws: 0\n",
"dummies/DropLowest victories: 2\n",
"dummies/SmartRandom victories: 1\n",
"draws: 0\n",
"----------------------------------\n",
"Final Board: \n",
"[[ 0 0 0 0 0 0 0 0]\n",
" [ 0 0 0 0 0 0 0 -1]\n",
" [ 0 0 0 0 0 1 0 -1]\n",
" [ 1 0 0 -1 0 1 0 -1]\n",
" [-1 0 0 -1 1 1 1 -1]\n",
" [ 2 2 2 -1 -1 -1 2 2]\n",
" [-1 1 1 1 -1 -1 1 -1]]\n",
" [ 0 0 0 0 0 0 0 0]\n",
" [ 0 0 0 0 0 0 0 0]\n",
" [ 0 0 0 0 0 0 0 0]\n",
" [ 0 0 0 0 0 0 0 0]\n",
" [ 0 -1 0 -1 -1 0 0 0]\n",
" [ 2 1 -1 -1 2 2 2 2]]\n",
"Moves: \n",
"[2, 7, 3, 0, 7, 3, 1, 7, 6, 3, 6, 5, 0, 5, 5, 7, 2, 4, 5, 3, 6, 4, 4, 0, 0, 7, 5, 7, 1]\n",
"Winner: dummies/Random\n",
"[0, 3, 1, 2, 4, 3, 5, 1, 6, 4, 7]\n",
"Winner: dummies/DropLowest\n",
"Reason: Connect 5!\n",
"----------------------------------\n",
"dummies/Random victories: 1\n",
"SmartRandom victories: 3\n",
"daws: 0\n",
"dummies/DropLowest victories: 3\n",
"dummies/SmartRandom victories: 1\n",
"draws: 0\n",
"----------------------------------\n",
"Final Board: \n",
"[[ 0 0 0 0 0 0 0 0]\n",
" [ 0 0 0 0 0 0 0 0]\n",
" [ 0 0 0 0 0 0 0 0]\n",
" [ 0 0 0 0 0 0 0 0]\n",
" [ 0 0 0 0 0 0 1 0]\n",
" [-1 -1 0 0 0 -1 1 0]\n",
" [ 2 2 2 2 2 -1 -1 -1]]\n",
" [-2 -2 1 0 0 -2 -2 -2]\n",
" [-1 1 -1 -1 -1 1 1 1]\n",
" [ 1 -1 1 -1 1 1 1 -1]\n",
" [ 1 1 1 1 -1 1 -1 -1]]\n",
"Moves: \n",
"[0, 6, 3, 5, 1, 0, 6, 7, 6, 5, 2, 1, 4]\n",
"Winner: dummies/Random\n",
"[0, 4, 1, 1, 2, 7, 3, 6, 5, 7, 0, 0, 2, 3, 4, 0, 5, 3, 6, 4, 1, 2, 5, 1, 6, 6, 7, 5, 2, 7]\n",
"Winner: dummies/SmartRandom\n",
"Reason: Connect 5!\n",
"----------------------------------\n",
"dummies/Random victories: 2\n",
"SmartRandom victories: 3\n",
"daws: 0\n",
"dummies/DropLowest victories: 3\n",
"dummies/SmartRandom victories: 2\n",
"draws: 0\n",
"----------------------------------\n"
]
}
Expand All @@ -194,7 +194,7 @@
" print('----------------------------------')\n",
" print(f'{p1} victories: {w}')\n",
" print(f'{p2} victories: {l}')\n",
" print(f'daws: {d}' )\n",
" print(f'draws: {d}' )\n",
" print('----------------------------------')"
]
},
Expand Down
Binary file modified players/__pycache__/dummies.cpython-311.pyc
Binary file not shown.

0 comments on commit e8ca910

Please sign in to comment.