def readGameBoard(self,startline): readBoard = True indexOfSpace = startline.index(' '); indexOfSemikolon = startline.index(','); xGameBoard = int(startline[indexOfSpace+1:indexOfSemikolon]) yGameBoard = int(startline[indexOfSemikolon+1:]) board = gameBoard.gameBoard(xGameBoard,yGameBoard) #read y zeilen mit x zeichen y = 0 while(readBoard): inputText = self.inputReader.read(); if(inputText == 'GAMEBOARDEND'): readBoard = False; else: for x in range(0,xGameBoard): board.setField(x,y,inputText[x:x+1]) y = y + 1 board.updateFloodCount() return board
def startGame(self): playchoice = input("Welcome to '4 in a row': Do you want to play against another Player (1) or the CPU (2)? 1/2") if playchoice == "1": self.computer = False elif playchoice == "2": self.computer = True else: print("Please choose one of the given options!") self.startGame() input("Press a Key to start the game") sp.call('cls',shell=True) self.gameEnded = False self.gameboard = gameBoard.gameBoard() #repeat moves for every player until someone has won while self.gameEnded == False: self.playerOneMove() if self.gameEnd() == True: break self.playerTwoMove() if self.gameEnd() == True: break self.playAgain()
def __init__(self, mapName): self.mapBoard = self.generateBoard(mapName) self.mapCharacters = self.generateCharacters(mapName) self.height = len(self.mapBoard) self.width = len(self.mapBoard[0]) self.gameboard = gameBoard(self.mapBoard, self.mapCharacters, self.height, self.width, self.mapLords) self.weights = [] self.ai = ai(self.gameboard, self.height, self.width, self.weights)
def startGame(self): self.colors=['blue','red'] self.Lines =[tk.PhotoImage(file='DottedLine.gif'),tk.PhotoImage(file='Line.gif'), tk.PhotoImage(file='HorizDottedLine.gif'),tk.PhotoImage(file='HorizLine.gif')] self.Dot =tk.PhotoImage(file='Dot.gif') self.Squares =[tk.PhotoImage(file='EmptySquare.gif'),tk.PhotoImage(file='BlueSquare.gif'),tk.PhotoImage(file='RedSquare.gif')] self.ActiveLines = [tk.PhotoImage(file='ActiveLine.gif'),tk.PhotoImage(file='ActiveHorizLine.gif')] self.ComLines = [tk.PhotoImage(file='ComLine.gif'),tk.PhotoImage(file='HorizComLine.gif')] self.t=0 self.counter=0 self.gb = gB.gameBoard(self.rows,self.cols) self.makeBoard()
def __init__(self, size=500, gameName='Reversi'): # initial game board print('initializing...') pygame.init() pygame.display.set_caption(gameName) self.size = size self.screen = pygame.display.set_mode( (self.size+self.size//5, self.size+self.size//5*2)) programIcon = pygame.image.load('Asset/images/icon.jpg') pygame.display.set_icon(programIcon) self.gameBoard = gameBoard(self.screen, size) # locate chess position, 0 for empty, 1 for black chess, -1 for white chess self.playingChessColor = 1 # initial chess positin self.gameBoard.setChessPos((3, 3), -1) self.gameBoard.setChessPos((3, 4), 1) self.gameBoard.setChessPos((4, 3), 1) self.gameBoard.setChessPos((4, 4), -1)
for x in viableSpaces: if self.squaresToMake(gb,x) < num: num = self.squaresToMake(gb,x) best = x return best else: for d in dontChoose: if len(viableSpaces)>1: if d in viableSpaces: viableSpaces.remove(d) random.shuffle(viableSpaces) return(viableSpaces[0]) return [-1,-1] if __name__ == "__main__": X=gb.gameBoard(3,3) for r in range(len(X.gridRepr)): for c in range(len(X.gridRepr[r])): X.gridRepr[r][c]=1 X.gridRepr[0][0]=0 X.gridRepr[0][1]=0 X.gridRepr[4][1]=0 X.gridRepr[5][2]=0 X.gridRepr[5][3]=0 X.gridRepr[2][1]=0 X.gridRepr[1][0]=0 c=-1 for x in X.gridRepr: c+=1 if c%2 == 0:
def __init__(self, inputReader): self.inputReader = inputReader self.gameBoard = gameBoard.gameBoard(1,1) self.round = r.gameRound() self.bot = bot.gameBot() self.flood = 0
import sys, pygame, display, gameBoard from pygame.locals import * #https://en.wikipedia.org/wiki/English_draughts boardObj = gameBoard.gameBoard() displayObj = display.displayObject(boardObj)
self.printLine(color, line) self.printVertMargin() def printVertMargin(self): for i in range(pref.VERT_MARGIN): self.printLine(tColors.ENDC, "") def printStatusMargin(self): for i in range(pref.STATUS_MARGIN): self.printLine(tColors.ENDC, "") def drawSeparator(self, color): line = "" for i in range(self.getScreenWidth()): line += "-" self.printLine(color, line) # tmp: test gui... graphics = terminalGui() board = gameBoard.gameBoard() graphics.redrawBoard(board) c = carrier() c.xPos = 3 c.yPos = 2 c.orientation = orient.EAST board.tryPlaceShip(c) time.sleep(3) graphics.redrawBoard(board)
def start(self): self.AI_turn = 'color' self.gb = gameBoard() self.isAI = False self.winTime = 0 self.rule = ValidRule(self.gb) choose = self.turn.get() self.draw_board() self.count_dict['color'] = self.maxCount self.count_dict['dot'] = self.maxCount self.step_dict['color'] = self.maxStep self.step_dict['dot'] = self.maxStep self.preCard = '' ifPuring = self.puring.get() if choose == 0: self.lable_turn['text'] = 'current turn: color' self.lable_turn['fg'] = 'red' self.current_turn = 'color' else: self.lable_turn['text'] = 'current turn: dot' self.lable_turn['fg'] = 'blue' self.current_turn = 'dot' if ifPuring == 0: self.isPuring = True else: self.isPuring = False self.isAuto = (self.auto.get() == 1) self.isAIFirst = (self.AIFirst.get() == 1 and self.isAuto) self.bt_color['state'] = DISABLED self.bt_dot['state'] = DISABLED self.bt_havePuring['state'] = DISABLED self.bt_noPuring['state'] = DISABLED self.bt_start['state'] = DISABLED self.bt_move['state'] = NORMAL self.entry_cmd['state'] = NORMAL self.lable_count['text'] = 'you have ' + str( self.count_dict[self.current_turn]) + ' cards left' self.lable_count['fg'] = 'red' self.bat_button['state'] = NORMAL self.batch_cmd['state'] = NORMAL self.entry_cmd.focus() #set cursor to input(entry_cmd) self.var_command.set('') self.lable_remind['text'] = 'regular mode' self.lable_remind['fg'] = 'red' self.cmd_list.delete(0, self.cmd_list.size()) self.check_Button['state'] = NORMAL if self.isAuto: if self.isAIFirst: self.AI_turn = self.current_turn else: if self.current_turn == 'color': self.AI_turn = 'dot' else: self.AI_turn = 'color' else: self.AIFirst.set(0) self.isAIFirst = False self.bt_AIFirst['state'] = DISABLED self.bt_auto['state'] = DISABLED if self.isAuto: self.bat_button['state'] = DISABLED if self.isAIFirst: self.AI_Move()