当前位置: 首页>>代码示例>>Python>>正文


Python Board.score方法代码示例

本文整理汇总了Python中board.Board.score方法的典型用法代码示例。如果您正苦于以下问题:Python Board.score方法的具体用法?Python Board.score怎么用?Python Board.score使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在board.Board的用法示例。


在下文中一共展示了Board.score方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: train

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import score [as 别名]
def train():
    i = input("How many games?")
    games = 0
    while games < i:
        if games > 5000 and games % 5000 == 0:
            f = open('Q/Q' + str(games) + '.p', 'w')
            pickle.dump(Q, f)
            f.close()
        game = Board(1, [[0, 0, 0], [0, 0, 0], [0, 0, 0]])
        last = game
        while not game.score():
            last = game
            game = choose_next_move(game)
            if game.score():
                Q[deep_tuple(correct_state(last))] = R(game)
                continue
            game = choose_next_move(game)
            Qvals = get_next_Qvals(game)
            Q[deep_tuple(correct_state(last))] = R(game) + gamma * max(Qvals)
        sys.stdout.write("\rGame #" + str(games + 1) + " completed.")
        sys.stdout.flush()
        games += 1
    print
    f = open('Q/Q.p', 'w')
    pickle.dump(Q, f)
    f.close()
    counter = 0
    for key, value in Q.iteritems():
        if value != 0:
            counter += 1
    print counter
开发者ID:KalyanPalepu,项目名称:tic-tac-toe-ai,代码行数:33,代码来源:qlearn.py

示例2: minimax_train

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import score [as 别名]
def minimax_train():
    i = input("How many games?")
    games = 0
    while games < i:
        if games > 100 and games % 100 == 0:
            f = open('Q/Q' + str(games) + '.p', 'w')
            pickle.dump(Q, f)
            f.close()
        game = Board(1, [[0, 0, 0], [0, 0, 0], [0, 0, 0]])
        while not game.score():
            last = game
            game, Qvals_first = choose_next_move(game)
            if game.score():
                Q[deep_tuple(correct_state(last))] = R(game) + gamma * max(Qvals_first)
                continue
            game = minimax.choose_next_move(game)
            Q[deep_tuple(correct_state(last))] = R(game) + gamma * max(Qvals_first)
        sys.stdout.write("\rGame #" + str(games + 1) + " completed.")
        sys.stdout.flush()
        games += 1
    f = open('Q/Q.p', 'w')
    pickle.dump(Q, f)
    f.close()
开发者ID:KalyanPalepu,项目名称:tic-tac-toe-ai,代码行数:25,代码来源:qlearn.py

示例3: new_game

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import score [as 别名]
def new_game():
    #setup
    print "                                      "
    print "                                      "
    print "                                      "
    print "            ### ################## ###"
    print "            ### Welcome to threes! ###"
    print "            ### ################## ###"
    print help_str
    board = Board(4)
    #game loop
    while True:

        print board
        choice = raw_input("(w, s, a, d, s, q, h?): ")

        if choice == 'w':
            board.shift('up')

        elif choice == 's':
            board.shift('down')

        elif choice == 'a':
            board.shift('left')

        elif choice == 'd':
            board.shift('right')

        elif choice == 'sc':
            print ""
            print "Your score: {0}".format(board.score())
            print ""

        elif choice == 'q':
            break

        elif choice == 'h':
            print help_str

        else:
            print help_str
开发者ID:bwarren2,项目名称:threes,代码行数:43,代码来源:threes.py

示例4: ReversiSimpleAI

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import score [as 别名]
ai = ReversiSimpleAI()

step = 0
while True:
    print '==============================='
    board = Board(game_server.get_board_state(game_id))
    board.pprint()

    x, y = ai.get_best_move(board, 1)
    
    state = game_server.move(x, y, game_id)

    step += 1

    board = Board(game_server.get_board_state(game_id))
    print '_______________________________'
    board.pprint()
    print state
    if state[1] == 'game_over':
        if board.score(1) > board.score(2):
            print "YOU'VE WON!!!", 'in ', step, 'steps'
        if board.score(1) == board.score(2):
            print 'EQUAL SCORE', 'in ', step, 'steps'
        if board.score(1) < board.score(2):
            print "YOU'VE LOST", 'in ', step, 'steps'
        
        print 'SCORE', board.score(1), board.score(2)
        break

print 'exiting'
开发者ID:korobool,项目名称:reversid,代码行数:32,代码来源:client.py

示例5: raw_input

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import score [as 别名]
from board import Board
from minimax import choose_next_move
import copy

print "Tic-Tac-Toe Minimax"
print
x = raw_input("Will you play first? (y/n)")
game = Board(1, [[0, 0, 0], [0, 0, 0], [0, 0, 0]])

if x == 'n':
    game = choose_next_move(game)
while game.winner is None:
    game.printState()
    move = map(int, raw_input('Your move:').split()) # expects "i j"
    new_state = copy.deepcopy(game.state)
    while len(move) != 2 or (move[0] - 1, move[1] - 1) not in game.empty():
        move = map(int, raw_input("Invalid Move.  Please try again:").split())
    new_state[move[0] - 1][move[1] - 1] = game.player
    game = choose_next_move(Board(-game.player, new_state))
    if x == 'n':
        game.score()
game.printState()
if game.winner == 0:
    print "It's a tie!"
else:
    print "You lose!"



开发者ID:KalyanPalepu,项目名称:tic-tac-toe-ai,代码行数:28,代码来源:game.py

示例6: print

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import score [as 别名]
         net_board_data += remain_data[:remain_size]
         
         remain_data = remain_data[remain_size:]
         remain_size = 0
         
         #net_board_data done
         #print (net_board_data)
         dic = json.loads(net_board_data.decode())
         #dic = pickle.loads(net_board_data)
         #print('Got one dic-->\n', dic)
         #print('-------------')
         net_board_data = b''
         
         tetris.board = dic['board']
         #tetris.block = dic['block']
         tetris.score = dic['score']
         
         tetris.block.ref_pos = dic['ref_pos']
         tetris.block.turn_type = dic['turn_type']
         tetris.block.turn_delta = dic['turn_delta']
         tetris.block.color_num = dic['color_num']
         tetris.block.block_type = dic['block_type']
         
         #print('dic : ref_pos -> ' ,dic['ref_pos'])
         #print('dic : turn_type -> ', dic['turn_type'])
         tetris.draw()
 
         # tetris.draw()
 elif remain_size < 0:
     print('error: remain_size should not negetive')
      
开发者ID:beardad1975,项目名称:tetrisAndCS,代码行数:32,代码来源:net_tetris_one_way_server.py

示例7: Board

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import score [as 别名]
                [0, 0, 0, 2, 1, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0]]


board = Board(initial_state)

print board.possible_moves(1)
print board.is_move_allowed(2, 3, 1)
directions = ((-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1))
for d in directions:
    print d, board.get_affected_checks((5, 3), d, 1)

#
initial_state = [[0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 1, 2, 0, 0, 0],
                [0, 0, 0, 2, 1, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0]]

board2 = Board(initial_state)
board2 = board2.move(5,3,1)
board2.pprint()
board2 = board2.move(5,2,2)
board2.pprint()
print board2.score(1), board2.score(2)
开发者ID:korobool,项目名称:reversid,代码行数:32,代码来源:debug_main.py

示例8: TestBoard

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import score [as 别名]
class TestBoard(TestCase):
    def setUp(self):
        self.board = Board()
        self.board2 = Board(False)
        King(Location(8, 'e'), Player.BLACK, self.board2)
        King(Location(1, 'e'), Player.WHITE, self.board2)

    def batch_move(self, board, moves):
        for move in moves:
            move = parse(board, move)
            self.board.move(move)

    def test_two_move_checkmate(self):
        moves = [
            'f2 f3',
            'e7 e5',
            'g2 g4',
            'd8 h4',
        ]
        self.batch_move(self.board, moves)

        self.assertTrue(self.board.checkmate())

    def test_draw(self):
        moves = [
            'c2 c4',
            'h7 h5',
            'h2 h4',
            'a7 a5',
            'd1 a4',
            'a8 a6',
            'a4 a5',
            'a6 h6',
            'a5 c7',
            'f7 f6',
            'c7 d7',
            'e8 f7',
            'd7 b7',
            'd8 d3',
            'b7 b8',
            'd3 h7',
            'b8 c8',
            'f7 g6',
            'c8 e6',
        ]
        self.assertFalse(self.board.draw())
        self.batch_move(self.board, moves)
        self.assertTrue(self.board.draw())
        self.assertFalse(self.board.checkmate())

    def test_en_passant(self):
        moves = [
            'a2 a4',
            'a7 a6',
            'a4 a5',
            'b7 b5',
        ]
        self.batch_move(self.board, moves)

        move = parse(self.board, 'a5 b6')  # white en passant attack
        self.assertTrue(move.en_passant)
        self.assertTrue(move in self.board.valid_moves())
        self.assertEquals(self.board.score(Player.WHITE), 0)
        self.board.move(move)
        self.assertEquals(self.board.score(Player.WHITE), Pawn.VALUE)
        self.board.undo_move()
        self.assertEquals(self.board.score(Player.WHITE), 0)

    def test_king_side_castle(self):
        moves = [
            'g1 h3',
            'a7 a6',
            'g2 g4',
            'b7 b6',
            'f1 g2',
            'c7 c6',
        ]
        self.batch_move(self.board, moves)

        move = parse(self.board, 'e1 g1')  # white
        self.assertTrue(move.castle)
        self.assertEquals(move.castle_side, Side.KING)
        self.assertEquals(str(move), 'O-O')
        valid_moves = list(self.board.valid_moves())
        self.assertTrue(move in valid_moves)
        self.board.move(move)

    def test_queen_side_castle(self):
        moves = [
            'b1 a3',
            'a7 a6',
            'b2 b4',
            'b7 b6',
            'c1 b2',
            'c7 c6',
            'c2 c4',
            'd7 d6',
            'd1 c2',
            'e7 e6',
        ]
#.........这里部分代码省略.........
开发者ID:zackee12,项目名称:command-line-chess,代码行数:103,代码来源:test_board.py

示例9: Board

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import score [as 别名]
initial_state = [[0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 1, 2, 0, 0, 0],
                [0, 0, 0, 2, 1, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0]]

board = Board(initial_state)

ai = RandomMoveAI()
current_player = 1

steps = 0
while board.has_moves(current_player):

    x, y = ai.get_best_move(board, current_player, Depth=4 - current_player)

    print('move:', steps, 'player:', current_player, 'action', (x, y))

    board = board.move(x, y, current_player)

    board.pprint()
    steps += 1
    # take a next player
    current_player = current_player % 2 + 1

print 'The End', 'SCORE 1:', board.score(1),'SCORE 2:', board.score(2)
开发者ID:korobool,项目名称:reversid,代码行数:31,代码来源:main.py

示例10: __init__

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import score [as 别名]
class GoServer:

    def __init__(self, IP='127.0.0.1', port=5005, BUFFER_SIZE=1024, size=19):
        self.TCP_IP = IP
        self.TCP_PORT = port
        self.BUFFER_SIZE = BUFFER_SIZE
        self.board = Board(size)
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.bind((self.TCP_IP, self.TCP_PORT))
        s.listen(1)
        self.size = size
        self.s = s

    def receive_players(self):
        self.conn = [None]*2
        self.addr = [None]*2

        for i in range(2):
            conn, addr = self.s.accept()
            print 'made connection %d: %s ' % (i, addr)
            self.conn[i] = conn
            self.addr[i] = addr

        self.game_num = {} # maps connection number {0, 1} to game number {1, 2}
        self.conn_num = {} # maps game number {1, 2} to connection number {0, 1}

        first_player_num = random.randint(1, 2)
        self.game_num[0] = first_player_num
        self.game_num[1] = 2 if first_player_num == 1 else 1

        self.conn_num[1] = 0 if first_player_num == 1 else 1
        self.conn_num[2] = 1 if first_player_num == 1 else 0

    def terminate(self):
        print 'closing connection'
        self.s.shutdown(socket.SHUT_RDWR)
        self.s.close()
        print 'connection closed'
        for conn in self.conn:
            if conn:
                conn.close()

    def run_game(self):
        for i in range(2):
            self.send('BEGINGAME %d %d\n' % (self.game_num[i], self.size), i)
        
        while True:
            curr_player = self.board.turn
            curr_conn_num = self.conn_num[curr_player]
            data = self.conn[curr_conn_num].recv(self.BUFFER_SIZE)
            if not data:
                break

            print 'received %s from %s' % (data, self.addr[curr_conn_num])
            if data.startswith('MAKEMOVE'):
                tokens = data.split()
                if len(tokens) == 3:
                    try:
                        i = int(tokens[1])
                        j = int(tokens[2])
                    except ValueError:
                        continue

                    if self.board.place_piece(i, j):
                        self.send_all('MADEMOVE ' + str(i) + ' ' + str(j) + '\n')
            elif data.startswith('PASSTURN'):
                if self.board.pass_turn():
                    self.send_all('PASSEDTURN' + '\n')
                    if self.board.gameover:
                        score_white, score_black = self.board.score()
                        self.send_all('GAMEOVER %d %d \n' % (score_black, score_white))
                        break
            elif data.startswith('QUIT'):
                self.board.gameover = True
                score_white, score_black = self.board.score()
                self.send_all('GAMEOVER %d %d \n' % (score_black, score_white))
                break
        print 'done serving'

    def send(self, message, player):
        self.conn[player].send(message)

    def send_all(self, message):
        for conn in self.conn:
            conn.send(message)
开发者ID:stevenhao,项目名称:wow,代码行数:87,代码来源:server.py


注:本文中的board.Board.score方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。