Exemplo n.º 1
0
    if letter == 'D':
        return 3
    if letter == 'E':
        return 4
    if letter == 'F':
        return 5
    if letter == 'G':
        return 6
    if letter == 'H':
        return 7

    raise ValueError("Invalid Character.")


board = board.Board.new()
print(board.to_string())

while True:
    move = get_valid_user_move(board)
    if (move == 0):
        if (board.is_check(pieces.Piece.WHITE)):
            print("Checkmate. Black Wins.")
            break
        else:
            print("Stalemate.")
            break

    board.perform_move(move)

    print("User move: " + move.to_string())
    print(board.to_string())
Exemplo n.º 2
0
			raise EOFError('sock closed {l} bytes into a {l2}-byte message'.format(l=len(data), l2 = length))
		data += more
	return data

def end_game(board, turn):
	if board.check_victory():
		print 'player',turn,'won'
		return True
	elif board.check_tie():
		print 'tie'
		return True
	else:
		return False

s.connect((HOST,PORT))
board = board.Board()
turn = board.turn

while True:
	print board
	input_var = raw_input(board.turn + " Enter [row, col]: ")
	if board.place_char(*[int(x.strip()) for x in input_var.split(',')]):
		print board
		s.sendall(board.to_string())
		turn = board.turn
		reply = recv_all(s,9)
		board.from_string(reply)
		if end_game(board, turn):
			print board
			break
s.close()