Skip to content
Open
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
7 changes: 5 additions & 2 deletions boardHelpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from collections import defaultdict
import StringIO
try:
from StringIO import StringIO ## for Python 2
except ImportError:
from io import StringIO ## for Python 3


def isInBounds(board, colIdx, rowIdx):
Expand Down Expand Up @@ -96,7 +99,7 @@ def getInARowMetric(board, symbol, allowBlanks=False):
def boardStr(board):
numCols = len(board)
numRows = len(board[0])
sio = StringIO.StringIO()
sio = StringIO()
for rowIdx in reversed(range(numRows)):
for colIdx in range(numCols):
symbol = board[colIdx][rowIdx] or '-'
Expand Down
2 changes: 1 addition & 1 deletion game.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def takeTurn(self, verbose=False, pause=False):
if verbose:
print(self)
if pause:
raw_input()
input()

class MoveOutOfRange(Exception):
pass
Expand Down
9 changes: 7 additions & 2 deletions player.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
boardStr
)

try:
BIG_NUM = sys.maxint # Python 2
except AttributeError:
BIG_NUM = sys.maxsize # Python 3


class Player(object):
def nextMove(self, board):
Expand All @@ -20,7 +25,7 @@ def nextMove(self, board):
moveChosen = False
while not moveChosen:
print(boardStr(board))
colIdx = raw_input('Which column?\n')
colIdx = input('Which column?\n')
try:
colIdx = int(colIdx)
except ValueError:
Expand Down Expand Up @@ -83,7 +88,7 @@ def miniMax(symbol, vsSymbol, board, heuristic, maxDepth, currentDepth):
else:
colIdxOptions = getAvailableColumns(board)
bestOptions = []
bestValue = -sys.maxint
bestValue = -BIG_NUM
for colIdx in colIdxOptions:
newBoard = applyMoveToNewBoard(board, colIdx, symbol)
newDepth = currentDepth + 1
Expand Down