Пример #1
0
    def set_result(self):
        if result(self._board) == 2:
            for b in self._boards:
                self.scores[hash_board(b[0], b[1])] -= 5
        elif result(self._board) == 1:
            for b in self._boards:
                self.scores[hash_board(b[0], b[1])] += 5
        elif result(self._board) == 0:
            for b in self._boards:
                self.scores[hash_board(b[0], b[1])] += 1

        if self._save_each_iteration:
            self.save_data(self.scores, self.LEARNING_DATA_PATH)
Пример #2
0
    def update(self, events):
        if not self.started or result(self.board) != -1:
            return

        if self.wait and time.time() < self.wait:
            return

        move = (-1, -1)
        if self.players[self.player_moving] == 'human':
            for event in events:
                if event.type == pygame.MOUSEBUTTONDOWN:
                    if event.button == 1:
                        mx = event.pos[0] - self.x
                        my = event.pos[1] - self.y
                        cs = self.cell_size
                        for y in range(len(self.board)):
                            for x in range(len(self.board)):
                                if my > y * cs and my < (y + 1) * cs \
                                    and mx > x * cs and mx < (x + 1) * cs:
                                    move = (x, y)
        else:
            if self.wait is None:
                self.wait = time.time() + 0.5
                return
            move = self.players[self.player_moving].get_move()

        if self.valid_move(move):
            self.board[move[1]][move[0]] = self.player_moving + 1
            next_player = (self.player_moving + 1) % 2
            if self.players[next_player] != 'human':
                self.players[next_player].opponent_move(move[0], move[1])
            self.player_moving = next_player

        self.wait = None
Пример #3
0
    def get_score(self, board, player_moving=True, depth=0):
        hash = hash_board(board, player_moving)

        if self._scores[hash] is not None:
            return self._scores[hash]

        res = result(board)
        if res == 1:
            self._scores[hash] = 100 - depth
            return 100 - depth
        if res == 2:
            self._scores[hash] = depth - 100
            return depth - 100
        if res == 0:
            self._scores[hash] = 0
            return 0

        possible_moves = self.get_possible_moves(board, player_moving)
        random.shuffle(possible_moves)
        best_score = None
        for move in possible_moves:
            score = self.get_score(move[0], not player_moving, depth + 1)
            if best_score is None \
                    or ((player_moving and score > best_score)
                        or (not player_moving and score < best_score)):
                best_score = score

        self._scores[hash] = best_score
        return best_score
Пример #4
0
def game(bet_value, player):
    color_list = ["Trèfle", "Coeur", "Pique", "Carrau"]
    value_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]

    deck = []

    for value in value_list:
        for color in color_list:
            new_card = Card(value, color)
            deck.append(new_card)

    selected_cards = random.sample(deck, 5)

    print("Vous avez tiré : \n")

    for selected_card in selected_cards:
        player.add_card(selected_card)
        deck.remove(selected_card)
        print(selected_card.get_name())

    final_card_list = []

    for card_tmp in player.get_card_list():
        choice = input("\nVoulez vous garder : " + card_tmp.get_name() +
                       " | oui/non ")
        if choice == "oui":
            final_card_list.append(card_tmp)
            print("ok, la carte est conservé")
        elif choice == "non":
            new_selected_card = random.sample(deck, 1)
            final_card_list.append(new_selected_card[0])
            deck.remove(new_selected_card[0])
            print("vous avez tiré :" + new_selected_card[0].get_name())
        else:
            final_card_list.append(card_tmp)
            print("Veleur incorrecte, la carte est conservé par défaut")

    player.update_all_cards(final_card_list)

    print("_______________________________________\n")
    print("Votre tirage final est : \n")

    for card_to_dispaly in player.get_card_list():
        print(card_to_dispaly.get_name())

    result(bet_value, player)
Пример #5
0
def play_single_game(players, player_moving=0):
    board = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

    while result(board) == -1:
        move = players[player_moving].get_move()

        if valid_move(board, move):
            board[move[1]][move[0]] = player_moving + 1
            next_player = (player_moving + 1) % 2
            players[next_player].opponent_move(move[0], move[1])
            player_moving = next_player
Пример #6
0
def game_finished(board, computer_symbol, human_symbol):
    res = result(board)
    if res == 2:
        print("You lost...")
        return True
    elif res == 1:
        print("You won! Congratulations!")
        return True
    elif res == 0:
        print("The game ended in a draw...")
        return True

    return False
Пример #7
0
    def get_move(self):
        possible_moves = self.get_possible_moves(self._board)
        random.shuffle(possible_moves)
        best_move = max(possible_moves,
                        key=lambda x: self.scores[hash_board(x[0], False)])

        self._board = best_move[0]
        self._boards.append((self._board, False))

        if result(self._board) != -1:
            self.set_result()

        return best_move[1]
Пример #8
0
    def render(self):
        self.fill((255, 255, 255))

        for x in range(1, len(self.board[0])):
            pygame.draw.line(self, (0, 0, 0), (x * self.cell_size, 0),
                             (x * self.cell_size, self.height))

        for y in range(1, len(self.board)):
            pygame.draw.line(self, (0, 0, 0), (0, y * self.cell_size),
                             (self.width, y * self.cell_size))

        for y in range(len(self.board)):
            for x in range(len(self.board[0])):
                if self.board[y][x] != 0:
                    line_width = 8
                    pad = self.cell_size * 0.1
                    x0 = x * self.cell_size + pad
                    x1 = (x + 1) * self.cell_size - pad
                    y0 = y * self.cell_size + pad
                    y1 = (y + 1) * self.cell_size - pad

                    if self.board[y][x] == 1:
                        pygame.draw.line(self, (0, 0, 0), (x0, y0), (x1, y1),
                                         line_width)
                        pygame.draw.line(self, (0, 0, 0), (x0, y1), (x1, y0),
                                         line_width)
                    elif self.board[y][x] == 2:
                        pygame.draw.ellipse(
                            self, (0, 0, 0),
                            pygame.Rect(x0, y0, x1 - x0, y1 - y0), line_width)

        res = result(self.board)
        if res != -1 or not self.started:
            s = pygame.Surface((self.width, self.height))
            s.set_alpha(128)
            s.fill((0, 0, 0))
            self.blit(s, (0, 0))

            font = pygame.font.SysFont(None, 40)
            label = None
            if res == 0:
                label = font.render('Draw!', True, (255, 255, 255))
            elif res == 1:
                label = font.render('Player 1 wins!', True, (255, 255, 255))
            elif res == 2:
                label = font.render('Player 2 wins!', True, (255, 255, 255))

            if label:
                x = (self.width / 2) - (label.get_width() / 2)
                y = (self.height / 2) - (label.get_height() / 2)
                self.blit(label, (x, y))
Пример #9
0
        def on_click():
            """Checking data and writing the results"""
            product = entryProduct.get()
            gram = entryGram.get()
            output.delete(0.0, END)

            Error = False
            try:
                gram = int(entryGram.get())
            except:
                Error = True
            try:
                x = int(product)
                Error = True
            except:
                pass
            if Error == True:
                messagebox.showerror("Error", "Please enter correct data!")
            else:
                functions.file_open()
                output.insert(END, functions.result(product, gram))
Пример #10
0
""" A program that implements the logic for a Tic-Tac-Toe game
    on an arbitrary size square board, e.g. 4x4, 5x5, etc.

    author: fizgi
    date: 23-Apr-2020
    python: v3.8.2
"""

from typing import List
from functions import initializer, print_board, row_checker, col_checker,\
    dgn_lr_checker, dgn_rl_checker, result

size, board = initializer()
winner_list: List[str] = []

print_board(board)

winner_list.extend(list(row_checker(board, size)))
winner_list.extend(list(col_checker(board, size)))
winner_list.extend(list(dgn_lr_checker(board, size)))
winner_list.extend(list(dgn_rl_checker(board, size)))

result(winner_list)
Пример #11
0
data = pd.read_csv('raw.csv')
#data=data.dropna()
data.pop('Unnamed: 24')
data = data.astype('object')
#data=data[:1000]

c2_avg = [
    'PTS', 'FGM', 'FGA', 'FG%', '3PM', '3PA', '3P%', 'FTM', 'FTA', 'FT%',
    'OREB', 'DREB', 'REB', 'AST', 'TOV', 'STL', 'BLK', 'PF', '+/-'
]

for ix in range(len(data)):
    print(ix)
    data1 = data.loc[ix, 'Game Date']
    team = data.loc[ix, 'Team']
    ixs = f.get_past_games(data, data1, team, 30)
    past = data.loc[ixs]
    data.at[ix, 'winrate 30'] = f.create_winrate(past, 30)
    data.at[ix, 'winrate 6'] = f.create_winrate(past, 6)

    for c in c2_avg:
        data.at[ix, c] = f.get_avgs(past, c)

data.to_csv('data.csv', index=False)

b = f.append2for1(data)
b['Result'] = f.result(b)
b['Location'] = f.location(b)

b.to_csv('train.csv', index=False)
Пример #12
0
    def opponent_move(self, x, y):
        self._board[y][x] = 2
        self._boards.append((self._board, True))

        if result(self._board) != -1:
            self.set_result()
Пример #13
0
toappend=toappend.astype('object')
for ix in range(len(toappend)):
  print(ix)
  data1=toappend.at[ix,'Game Date']
  team=toappend.at[ix,'Team']
  past=f.get_past_games(whole_data,data1,team,20)
  toappend.at[ix,'winrate 20']=f.create_winrate(past,20)
  toappend.at[ix,'winrate 10']=f.create_winrate(past,10)
  toappend.at[ix,'winrate 5']=f.create_winrate(past,5)
  toappend.at[ix,'fatigue']=f.fatigue(past)
  for c in c2_avg:
    toappend.at[ix,c]=f.get_avgs(past,c)
"""
# update data.csv
data=pd.read_csv('data.csv')
data=data.dropna()
data=data.iloc[::-1]
data=data.append(toappend,sort=False)
data=data.iloc[::-1]
data=data.reset_index(drop=True)
data.to_csv('data.csv',index=False)
"""
# update train.csv
train=pd.read_csv('train.csv')
toappend=f.append2for1(toappend)
toappend['Result']=f.result(toappend)
train=train.iloc[::-1]
train=train.append(toappend,sort=False)
train=train.iloc[::-1]
train.to_csv('train.csv',index=False)