def ac_play(reversi, dom, id): xy = [int(id[1]), int(id[0])] bw = reversi.bw token = reversi.token if token: # HH mode if bw == core.EMPTY: if not take_black(token): set_status(dom, "Wait for the opponent's move.", "red") reversi.bw = core.WHITE draw_board(reversi, dom, False) return reversi.bw = core.BLACK bw = core.BLACK board = get_board(token) if board: if board.put(xy[0], xy[1], bw): set_turn(token, bw * -1) atlastk.broadcastAction("Refresh", token) else: set_status(dom, "Game interrupted!", "blue") else: board = reversi.board if (board.put(xy[0], xy[1], bw)): draw_board(reversi, dom) computer_move(reversi, dom) test_eog(board, dom, bw)
def acSubmitMessage(chatroom, dom): message = dom.getValue("Message") dom.setValue("Message", "") dom.focus("Message") chatroom.addMessage(chatroom.pseudo, message) chatroom.displayMessages(dom) atlastk.broadcastAction("Update")
def acDealerMove(dom, id): global leaderId, dealerHand, money, bet displayHand(dom, 'dealer', dealerHand, True) notify(dom, "Dealer plays.") with lock: leader = id == leaderId if leader: leaderId = str(uuid.uuid4()) if leader: notification = 0 dealerHandValue = getHandValue(dealerHand) playerHandValue = getHandValue(playerHand) if dealerHandValue > 21: money += bet notification = 5 elif dealerHandValue > playerHandValue: money -= bet notification = 8 if money > 0 else 9 elif dealerHandValue == playerHandValue and dealerHandValue >= 17: notification = 7 if notification: bet = -bet # To report end of turn. atlastk.broadcastAction("RefreshDisplay", "M{}".format(notification)) else: dealerHand.append(deck.pop()) time.sleep(1) atlastk.broadcastAction("DealerMove", leaderId)
def acSubmit(dom, id): global gameBoard, playerTurn columnIndex = int(id) # If the column is full, ask for a move again: if gameBoard[(columnIndex, 0)] != EMPTY_SPACE: notify(dom, 'That column is full, select another one.') return # Starting from the bottom, find the first empty space. for rowIndex in range(BOARD_HEIGHT - 1, -1, -1): if gameBoard[(columnIndex, rowIndex)] == EMPTY_SPACE: playerMove = (columnIndex, rowIndex) break gameBoard[playerMove] = playerTurn # Switch turns to other player: if playerTurn == PLAYER_X: playerTurn = PLAYER_O elif playerTurn == PLAYER_O: playerTurn = PLAYER_X atlastk.broadcastAction("Display")
def ac_play(player, dom, id): global board, turn, available x, y = int(id[0]), int(id[1]) bw = player.bw if not is_allowed(board, x, y, bw or turn or BLACK): return if turn == None: turn = BLACK if bw == None: bw = player.bw = turn available = turn == BLACK if (bw != EMPTY) and bw == turn: for delta in reversible_directions(board, bw, x, y): reverse_piece(board, bw, x, y, delta[0], delta[1]) board[x][y] = bw turn = turn * -1 atlastk.broadcastAction("Refresh")
def acHit(dom): global money, bet if not testAction(dom, 'H', playerHand, bet): return playerHand.append(deck.pop()) handValue = getHandValue(playerHand) if handValue == 21: atlastk.broadcastAction("RefreshDisplay", 'P0') letDealerPlay() else: view = "P" if handValue > 21: money -= bet bet = -bet notification = 8 if money > 0 else 9 view += "M" else: # handValue < 21 notification = 3 atlastk.broadcastAction("RefreshDisplay", '{}{}'.format(view, notification))
def acSubmit(dom, id): global movesLeft if not hasWon(gameBoard) and movesLeft != 0: changeTile(int(dom.getAttribute(id, "data-tile")), gameBoard, 0, 0) movesLeft -= 1 atlastk.broadcastAction("Display")
def acResume(dom): if not testAction(dom, 'R', playerHand, bet): return if money > 0: newTurn() else: newGame() atlastk.broadcastAction("RefreshDisplay", 'dpMB1')
def acSubmitMessage(session,dom): room = session.room message = dom.getValue("Message") dom.setValue("Message", "") dom.focus("Message") room.addMessage(session.pseudo,message) room.displayMessages(session,dom) atlastk.broadcastAction("Update")
def acDelete(board,dom): if board.contactId == None: raise Exception("No contact selected!") contacts.pop(board.contactId) board.contactId = None; displayContact(None,dom) updateOutfit(board,dom) atlastk.broadcastAction("Refresh")
def acBet(dom): global dealerHand, playerHand if not testAction(dom, 'B', playerHand, bet): return dealerHand = [deck.pop(), deck.pop()] playerHand = [deck.pop(), deck.pop()] atlastk.broadcastAction("RefreshDisplay", 'dP2') if getHandValue(playerHand) == 21: letDealerPlay()
def acSub(dom, id): global money, bet if not testAction(dom, '-', playerHand, bet): return value = int(dom.getMark(id)) if value > bet: notify(dom, "You can't to remove that much!") return bet -= value notify(dom, "Bet down by {} to {}.".format(value, bet)) atlastk.broadcastAction("RefreshDisplay", 'B0')
def acAdd(dom, id): global money, bet if not testAction(dom, '+', playerHand, bet): return value = int(dom.getMark(id)) if (value + bet) > money: notify(dom, "You can't bet that much!") return bet += value notify(dom, "Bet raised by {} to {}.".format(value, bet)) atlastk.broadcastAction("RefreshDisplay", 'B0')
def acSubmit(dom, id): global gameBoard, playerTurn response = id # Make sure it is a valid pit to select: if ( playerTurn == '1' and response not in PLAYER_1_PITS )\ or ( playerTurn == '2' and response not in PLAYER_2_PITS ): notify(dom, 'Please pick a pit on your side of the board.') return if gameBoard.get(response) == 0: notify(dom, 'Please pick a non-empty pit.') return playerTurn = makeMove(gameBoard, playerTurn, response) atlastk.broadcastAction("Display")
def acSubmit(board,dom): idsAndValues = dom.getValues(fields) if not idsAndValues['Name'].strip(): dom.alert("The name field can not be empty!") return if board.contactId == None or board.contactId >= len(contacts): contacts.append(idsAndValues) displayContact(None,dom) else: contacts[board.contactId] = idsAndValues atlastk.broadcastAction("Refresh") board.state = State.DISPLAY updateOutfit(board,dom)
def acDoubleDown(dom): global money, bet, playerHand if not testAction(dom, 'D', playerHand, bet): return value = min(bet, money - bet) if value == 0: notify(dom, "Not enough money to double down!") return bet += value playerHand.append(deck.pop()) if getHandValue(playerHand) > 21: money -= bet bet = -bet atlastk.broadcastAction("RefreshDisplay", 'MBP{}'.format(8 if money >= 0 else 9)) else: atlastk.broadcastAction("RefreshDisplay", 'BP1') letDealerPlay()
def letDealerPlay(): global leaderId leaderId = str(uuid.uuid4()) atlastk.broadcastAction("DealerMove", leaderId)
def acNew(dom): newGame() atlastk.broadcastAction("Display")
def ac_new(dom): init() atlastk.broadcastAction("Refresh")
def acNew(dom): newGame() atlastk.broadcastAction("RefreshDisplay", 'dpMB1')
def broadcast(token): atlastk.broadcastAction("Display", token)
def _reset(self): if self.token: remove(self.token) atlastk.broadcastAction("Refresh", self.token)