# A two-player board game, like tic-tac-toe, chess, etc:

### Data structure and its maintenance functions (connection points).
###   This part should probably be placed in its own module.

size = 9       # the board's size
EMPTY = "_"    # how we represent an empty space

# build the board:
board = []
for i in range(size):    # counts from 0 upto the  size
    board = board + [ size * [EMPTY] ]


def ok(index) :
    """ok  is a helper function 
       returns True if  index  falls in the bounds of board; 
       returns False otherwise
    """
    return (index >= 0) and (index < size)


def insert(who, row, col):
    """insert tries to insert a mark from player  who  at position  row,col  in the board
       parameters: who - a string ("X" or "O");  
                   row, col - ints, must be within the bounds of the board
       returns: True, if the move is successful; returns False, otherwise
    """
    global board
    successful_move = False
    if ok(row) and ok(col) :
        if board[row][col] == EMPTY :
            board[row][col] = who
            successful_move = True
    return successful_move


def printBoard():
    """printBoard  prints a representation of the board on the display"""
    global board
    for row in board :
        for square in row :
            print square,
        print
    print


###### The program's controller: ###

def makeMove(who) :
    """makeMove gets a player's next move and tries to make the move.
       parameter: who - a string identifying the player ("X" or "O")
    """
    move = raw_input("Player " + who + " : Type the coordinates of the move: ")
    coordinates = move.split(",")
    row_coordinate = int(coordinates[0])
    column_coordinate = int(coordinates[1])
    insert(who, row_coordinate, column_coordinate)  

game_on = True

while game_on :
    printBoard()
    makeMove("X")
    makeMove("O")

printBoard()
