示例#1
0
    def __init__(self,
                 name1,
                 name2,
                 num_cards=10):  #קונסטרקטור זה מכנס לתוכו את את שאר הקלאסיםץ
        #הוא מקבל שמות שחקנים ומספק קלפים מאמת שאכן השמות תקינים ןשמספר הקלפים תקין מייצר שחקנים שבמות אלה וקורא לפונקציה new game

        self.deckK = Deck_Of_Cards()
        if not self.validate_name(name1):
            print("error in name 1")
            return
        if not self.validate_name(name2):
            print("error in name 2")
            return
        if name1 == name2:
            name1 += ".A"
            name2 += '.B'
        if type(num_cards) != int or num_cards < 10:
            print("invalid card number")
            return
        player1 = Player(name1, num_cards)
        player2 = Player(name2, num_cards)
        self.player1 = player1
        self.player2 = player2
        self.numCards = num_cards
        self.new_game_called = False
        self.new_game()
示例#2
0
def calc_comprehensive_Elo(tournament_data, player_ratings):
    for games in tournament_data:
        for game in games['games']:
            temp_winner = game['winner']
            assert temp_winner in game['players'] and len(game['players']) == 2
            temp_loser = next(filter(lambda x: x != temp_winner, game['players']))

            for each in player_ratings:
                if temp_winner == each.name:
                    winner = each
                if temp_loser == each.name:
                    loser = each

            new_ratings = EloRating(winner.Elo, loser.Elo, 40)
            winner.Elo = new_ratings[0]
            loser.Elo = new_ratings[1]

    player_ratings = [Player.round_Elo(each) for each in player_ratings]
示例#3
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
from class_player import Player

#Clear screen before the game
os.system('cls' if os.name == 'nt' else 'clear')

pseudo = str(input("Entrez le pseudo du premier joueur : "))
player1 = Player(1, pseudo)
os.system('cls' if os.name == 'nt' else 'clear')

pseudo = str(input("Entrez le pseudo du second joueur : "))
player2 = Player(2, pseudo)
os.system('cls' if os.name == 'nt' else 'clear')

bEndGame = False
playerToPlay = 1

while bEndGame == False:
    if playerToPlay == 1:
        player1.printGameboard()
        print("Joueur 1, à toi de jouer !")
        posFire = player1.play()
        posX = 0
        posY = ''
        posYInt = 0

        #print("[DEBUG] posFire : " + str(posFire))
示例#4
0
    def server_listener(self):
        server_data = self.conn.receive(False)
        if server_data:
            server_data = server_data.split('|')
            if server_data[0] == "loadmap":  # Map loading / set player pos
                self.load_map(server_data[1])
                if server_data[2] == "spawn":
                    self.player.set_pos(self.map.spawnpos[0],
                                        self.map.spawnpos[1])
                else:
                    pl_pos = server_data[2].split('/')
                    self.player.set_pos(int(pl_pos[0]), int(pl_pos[1]))
                if not self.map_updated:
                    self.map_updated = True

            elif server_data[0] == "new_pl":  # Create new player
                newplayer = Player(int(server_data[1]), self.map.spawnpos,
                                   int(server_data[2]))
                self.playerlist[int(server_data[1])] = newplayer

            elif server_data[0] == "remove_pl":  # Remove player
                try:
                    tmp_player = self.playerlist[int(server_data[1])]
                except NameError:
                    pass
                else:
                    self.playerlist.pop(int(server_data[1]), None)
                    self.remove_player_sprite(tmp_player)

            elif server_data[0] == "update_pl":  # Update player position
                try:
                    self.playerlist[int(server_data[1])].set_pos(
                        int(server_data[2]), int(server_data[3]))
                except KeyError:
                    pass

            elif server_data[0] == "pl_chat":  # Player chats
                plname = server_data[1]
                if server_data[2] == "local":
                    self.chat_log(plname + ": " + server_data[3],
                                  (255, 255, 102))
                elif server_data[2] == "global":
                    self.chat_log(plname + " [global]: " + server_data[3],
                                  (255, 102, 0))
                elif server_data[2] == "whisper":
                    self.chat_log(plname + " [whisper]: " + server_data[3],
                                  (153, 102, 255))

            elif server_data[0] == "msg":  # Basic message from server
                col = [int(c) for c in server_data[2].split(',')]
                self.chat_log(server_data[1], col)

            elif server_data[0] == "setstat_pl":  # Update player stat
                pl_id = int(server_data[1])
                values = server_data[2:]
                for val in values:
                    val = val.split('/')
                    try:
                        val[1] = int(val[1])
                    except ValueError:
                        try:
                            val[1] = float(val[1])
                        except ValueError:
                            pass

                    if pl_id == -1:
                        self.player.set_stat(val[0], val[1])
                    else:
                        try:
                            self.playerlist[pl_id].set_stat(val[0], val[1])
                        except KeyError:
                            pass

            elif server_data[0] == "pong":  # Keeps connection alive
                self.ping_timeout = 0
from class_player import Player
from Deck_of_cards import Deck_Of_Cards
from card_game import CardGame
card = CardGame('tom', 'itay')
tom = Player('tom', 10)
deck = Deck_Of_Cards()

print(len(deck.card_list))

for i in range(11):
    tom.getCard()
示例#6
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
from class_player import Player

#Clear screen before the game
os.system('cls' if os.name == 'nt' else 'clear')

pseudo = str(input("Entrez le pseudo du premier joueur : "))
player1 = Player(1, pseudo)
os.system('cls' if os.name == 'nt' else 'clear')

pseudo = str(input("Entrez le pseudo du second joueur : "))
player2 = Player(2, pseudo)
os.system('cls' if os.name == 'nt' else 'clear')


bEndGame = False
playerToPlay = 1

while bEndGame == False:	
	if playerToPlay == 1:
		player1.printGameboard()
		print("Joueur 1, à toi de jouer !")
		posFire = player1.play()
		posX = 0
		posY = ''
		posYInt = 0

		#print("[DEBUG] posFire : " + str(posFire))
示例#7
0
    '-o',
    dest='outDir',
    type=Path,
    metavar='OUT_DIR',
    default=Path("./Player_Ratings/"),
    help='Generated ratings go here. Default: ./Player_Ratings/')
args = parser.parse_args()
if args.dataDir is not None:
    path = args.dataDir
else:
    # Read in the file path from the JSON file
    with open('path.json') as pathfile:
        p = json.load(pathfile)
        path = Path(p["path"])

# Create the tournament and player information lists
tournament_data = load_ordered_tournaments(path)
player_names = load_all_players(tournament_data)

# Create new ratings for each player
player_Elo_ratings = [Player(each) for each in player_names]

# TODO add more data points listed in the Player class
# Calculate and sort player Elo ratings from highest to lowest
calc_comprehensive_Elo(tournament_data, player_Elo_ratings)
player_Elo_ratings.sort(key=lambda p: -p.Elo)

args.outDir.mkdir(exist_ok=True)
# Creates the JSON from the player_ratings list
player_ratings_to_JSON(player_Elo_ratings, args.outDir / "Elo_ratings.json")
示例#8
0
import time
import datetime
from class_player import Player
from class_session import Session
from class_money import Money
from class_player_admin import Player_admin

curr_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print(curr_time)

player1 = Player('a1@b', 'name1', 'psw_2')
print(player1.login)
player1.save_to_db()

session1 = Session('a1@b')
session1.save_to_db()
print('session start time is {}'.format(session1.time_start))

player2 = Player('a2@b', 'name2', 'psw_2')
print(player1.login)
player1.save_to_db()

player3 = Player('a1@b')
player3.load_from_db()
print('player psw is {}'.format(player3.psw))

money_p1_usd = Money('a1@b', 'usd', 200)
money_p1_usd.save_to_db()

money_p2_usd = Money('a1@b', 'usd')
money_p2_usd.load_from_db()
示例#9
0
 def setUp(self):
     self.player = Player('tom', )
     self.deck1 = Deck_Of_Cards()
示例#10
0
class TestPlayer(TestCase):
    def setUp(self):
        self.player = Player('tom', )
        self.deck1 = Deck_Of_Cards()

    def test_setHand(
        self
    ):  #בדיקה שאכן חולקו עשרה קלפים לשחקן ושהקלפים האלה כבר לא חיימים בחפיסה המקורית ממנה הם נשלפו
        self.player.setHand(self.deck1)
        self.assertEqual(len(self.player.package.card_list), 10)
        for i in self.player.package.card_list:
            x = i in self.deck1.card_list
        self.assertTrue(True, x)

    def test_getCard_empty_list(
            self):  #בדיקה מה קורה שכאשר אין יותר קלפים ביד השחקן ושולפים קלף
        for i in range(10):
            self.player.getCard()
        self.assertIsNone(self.player.getCard(), None)

    def test_getCard(
            self):  #בדיקה שהפונקציה שולפת את הקלף הנכון מתוך היד של השחקן
        self.player.setHand(self.deck1)
        self.assertTrue(self.player.getCard(),
                        self.player.package.card_list[0])

    def test_addCard_invalid_type(
            self):  #הפונקציה מסוגלת להוסיף רק קלפים לרשימת השחקן
        self.assertFalse(self.player.addCard('tom'), True)

    def test_addCard(self):  #הפונקציה מסוגלת להוסיף קלפים ליד השחקן
        x = self.deck1.card_list.pop()
        self.player.addCard(x)
        self.assertEqual(self.player.package.card_list[0], x)