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


Python Board.put_piece方法代码示例

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


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

示例1: Board

# 需要导入模块: import Board [as 别名]
# 或者: from Board import put_piece [as 别名]
#!/usr/local/bin/env python3
# -*-coding:utf-8 -*

from Board import *
from Piece import *
from QTree import *
import copy

testBoard = Board()
# print(testBoard.__dict__)
testBoard2 = copy.deepcopy(testBoard)
testBoard2.put_piece(1, 1, testBoard.list_pieces[2])
testBoard.put_piece(1, 1, testBoard.piecesRemaining[0])
testBoard.put_piece(1, 2, testBoard.piecesRemaining[0])
moveChoice = QTree(testBoard, "square",
                   chosenPiece=testBoard.piecesRemaining[0])
moveChoice.add_level()
moveChoice.add_level()
moveChoice.add_level()
moveChoice.update_score()
bestChoice = moveChoice.leaf[0]
for leaf in moveChoice.leaf:
    if leaf.score > bestChoice.score:
        bestChoice = leaf
print(bestChoice.score)
for leaf in bestChoice.leaf:
    print(leaf.score)
    print(leaf.aiTurn)

开发者ID:punpen,项目名称:Quarto,代码行数:30,代码来源:Qtest.py

示例2: Main_game_display

# 需要导入模块: import Board [as 别名]
# 或者: from Board import put_piece [as 别名]
class Main_game_display(tkinter.Tk):

    def __init__(self, parent, player1, player2, mode):
        tkinter.Tk.__init__(self, parent)
        self.parent = parent
        self.initialize(player1, player2, mode)

    def initialize(self, player1, player2, mode):
        # player_main is the main player
        self.player1 = player1
        self.player2 = player2
        self.player_main = self.player1
        self.mode = mode
        self.grid()
        # definition of pieces and board area
        self.define_pieces()
        self.define_board()
        # selection of the a piece
        # By default no piece is selectioned
        self.selection = 16
        self.chosenPiece = Piece()
        # texts and butons of the game
        self.topTitle = tkinter.Label(self, text=u"Quarto")
        self.topTitle.grid(column=0, row=0, columnspan=7)
        self.text_instruction = tkinter.StringVar()
        self.text_instruction.set("{}, select a piece and click \
on SELECT".format(self.player_main))
        self.instruction = tkinter.Label(self,
                                         textvariable=self.text_instruction)
        self.instruction.grid(column=0, columnspan=6, row=6)
        self.instruction_selec = tkinter.Label(self,
                                               text=u"Piece selected :")
        self.instruction_selec.grid(column=0, columnspan=2, row=9)
        self.image_selec = self.image_empty
        self.canvas_selec = tkinter.Canvas(self, width=60, height=60)
        self.canvas_selec.create_image(30, 30, image=self.image_selec)
        self.canvas_selec.grid(column=3, row=9)
        self.button_selec = tkinter.Button(self,
                                           text=u"SELECT",
                                           command=self.select)
        self.button_selec.grid(column=4, columnspan=2, row=9)
        self.geometry('{}x{}'.format(650, 600))
        self.gridsize()
        self.resizable(width=False, height=False)

    def gridsize(self):

        self.columnconfigure(0, minsize=10, weight=1)
        self.rowconfigure(0, minsize=10)
        self.columnconfigure(1, minsize=60, weight=0)
        self.rowconfigure(1, minsize=10)
        self.columnconfigure(2, minsize=60, weight=0)
        self.rowconfigure(2, minsize=60)
        self.columnconfigure(3, minsize=60, weight=0)
        self.rowconfigure(3, minsize=60)
        self.columnconfigure(4, minsize=60, weight=0)
        self.rowconfigure(4, minsize=60)
        self.columnconfigure(5, minsize=10, weight=1)
        self.rowconfigure(5, minsize=60)
        self.columnconfigure(6, minsize=60, weight=0)
        self.rowconfigure(6, minsize=60)
        self.columnconfigure(7, minsize=60, weight=0)
        self.rowconfigure(7, minsize=60)
        self.rowconfigure(8, minsize=60)
        self.rowconfigure(9, minsize=60)

    def define_board(self):
        self.board = Board()
        self.button_square = []
        self.image_square = []
        self.image_empty = tkinter.PhotoImage(file='empty.gif')
        i = 0
        while i < 16:
            self.image_square.append(self.image_empty)
            self.button_square.append(tkinter.Button(
                                                     self))
            self.button_square[i].config(
                                       image=self.image_square[i],
                                       command=lambda i=i: self.put_piece(i),
                                       width="60", height="60")
            self.button_square[i].grid(column=(i % 4)+1, row=(i//4)+2)
            i += 1

    def define_pieces(self):
        self.v = tkinter.IntVar()
        self.v.set(16)
        self.pieces = []
        self.image_pieces = []
        i = 0
        while i < 16:
            self.pieces.append(tkinter.Radiobutton(
                                                   self, variable=self.v,
                                                   indicatoron=0,
                                                   value=i))
            self.pieces[i].grid(column=6+(i//8), row=(i % 8)+2)
            imageToLoad = 'Piece' + str(i) + '.gif'
            self.image_pieces.append(tkinter.PhotoImage(file=imageToLoad))
            self.pieces[i].config(
                                 image=self.image_pieces[i],
                                 width="60", height="60")
#.........这里部分代码省略.........
开发者ID:punpen,项目名称:Quarto,代码行数:103,代码来源:Main_game_display.py


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