Beispiel #1
0
 def __init__(self, names):
     self.pack = Pack()
     self.nbPlayers = len(names)
     self.players = []
     for i in range(self.nbPlayers):
         self.players.append(Player(names[i]))
     toDistribute = self.pack.distribute(self.nbPlayers)
     for i in range(len(toDistribute)):
         for j in toDistribute[i]:
             self.players[i].recieve(j)
     self.pile = Pile(self.pack.pick())
     self.turn = 0
     self.clockwise = True
Beispiel #2
0
class GM:
    def __init__(self, names):
        self.pack = Pack()
        self.nbPlayers = len(names)
        self.players = []
        for i in range(self.nbPlayers):
            self.players.append(Player(names[i]))
        toDistribute = self.pack.distribute(self.nbPlayers)
        for i in range(len(toDistribute)):
            for j in toDistribute[i]:
                self.players[i].recieve(j)
        self.pile = Pile(self.pack.pick())
        self.turn = 0
        self.clockwise = True

    def addPlayer(self, name):
        newPlayer = Player(name)
        self.nbPlayers += 1
        for i in self.pack.distribute(1)[0]:
            newPlayer.recieve(i)
        self.players.append(newPlayer)

    def showHands(self):
        for i in self.players:
            print(i.showHand())

    def showGame(self):
        print(self.pack.showPack())
        self.showHands()

    def playTurn(self):
        p = self.players[self.turn]
        print("It is " + p.name + "'s turn to play")
        print("your hand:", p.showHand())
        print('pile:', self.pile.showTop())
        print(
            "what would you like to do ? (type your action, no additional instructions given)"
        )
        action = input()
        if ("pick" in action):
            c = self.cards.pick()
            if (c == "no cards"):
                self.cards.add(self.pile.empty())
                c = self.cards.pick()
            p.recieve(c)
            print(p.name + " has recieved:", c)
        elif ("place" in action or "put" in action):
            pass
Beispiel #3
0
    def __init__(self):
        self.piles = [Pile(suit) for suit in HungarianDeck.suits]
        self.setup_players('Máté')

        self.is_first_card = True
        self.on_turn = 0
        self.starter = randint(0, self.NUMBER_OF_PLAYERS - 1)
        self.succesful_buys = 0
Beispiel #4
0
class Player:
    def __init__(self, Name):
        self.Name = Name
        self.Hand = Pile()
        self.Pile = Pile()

    def __repr__(self):
        Output(f"Player: {self.Name}")
        Output("  Current Hand")
        Output("  ------------")
        Output(self.Hand)
        Output("")
        Output("  Current Pile")
        Output("  ------------")
        Output(self.Pile)
        return ""

    def GetName(self):
        return self.Name

    def GetPile(self):
        return self.Pile

    def GetHand(self):
        return self.Hand

    # Deal a hand to this player based on the Pile for the game which
    # is provided as an input
    #
    def DealHand(self, GamePile):
        Cards = GamePile.Deal(4)
        self.Hand.Reset()
        for Card in Cards:
            self.Hand.AddCard(Card)

    # Add cards to a player's pile that were taken down from board.  The piles on the
    # board will be represented as Piles as will the player's pile.
    #
    def AddToPile(self, Cards):
        self.Pile.AddCards(Cards)
Beispiel #5
0
	def play(self):
		cd = CardDeck()
		cd.shuffle()
		self.__p1 = Player('Player1')
		self.__p2 = Player('Player2')
		while(cd.getSize() >= 2):
			self.__p1.collectCard(cd.deal())
			self.__p2.collectCard(cd.deal())
		self.__p1.useWonPile()
		self.__p2.useWonPile()
		down = Pile()
		for t in range(1, 101):
			if(not(self.enoughCards(1))): break
			c1 = Card(None,None)
			c2 = Card(None,None)
			c1 = self.__p1.playCard()
			c2 = self.__p2.playCard()
			print("\nTurn ", t, "!")
			print(self.__p1.getName() ,": ", c1, " ")
			print(self.__p2.getName() ,": ", c2, " ")
			if(c1.compareTo(c2) > 0):
				self.__p1.collectCard(c1)
				self.__p1.collectCard(c2)
			elif(c1.compareTo(c2) < 0):
				self.__p2.collectCard(c1)
				self.__p2.collectCard(c2)
			else:
				down.clear()
				down.addCard(c1)
				down.addCard(c2)
				done = False
				while(not(done)):
					num = c1.getRank()
					if(not(self.enoughCards(num))): break
					print("\nWar! Players put down ")
					print(num , " cards(s).")
					for m in range(1, num+1):
						c1 = self.__p1.playCard()
						c2 = self.__p2.playCard()
						down.addCard(c1)
						down.addCard(c2)
					print(self.__p1.getName(), ": ", c1, " ")
					print(self.__p2.getName(), ": ", c2, " ")
					if(c1.compareTo(c2) > 0):
						self.__p1.collectCards(down)
						done = True
					elif(c1.compareTo(c2) < 0):
						self.__p2.collectCards(down)
						done = True
			print(self.__p1.numCards(), " to ", self.__p2.numCards())
Beispiel #6
0
def runSimu(Lz, ds):
    Lx = 1  # length in x
    Ly = 1  # length in y
    dx = 0.07  # grid spacing m
    dt = 30  # seconds
    #initialT = 20
    filename = "3d-dis/-H-%.2fm-ds-%.2f%%-2mol-20-collapse" % (Lz, ds)
    print(filename)

    #meshTemp = np.full((round(Lx/dx), round(Ly/dx)), 20, dtype='float64') # initial temperature in C
    #setBoundaryCondition(meshTemp, 10, 15, 10, 10)
    pile = Pile(Lx, Ly, Lz, dx, dx, dx, 273 + 20, ds)
    initialMass = pile.mass
    #pile.loadFields()
    steps = 800
    start = 0
    log_step = 25
    time_stamps = []
    ATemp = []
    Temp = []
    Oxygen = []
    Bacteria = []
    Mass = []
    print("percentage mass,TIME(h),HEIGHT,TEMP0,TEMP,OXY,BAC,MASS")
    timeNow = 0
    for i in range(start, start + steps):
        ambientT = 10 * np.sin(2 * np.pi / (24 * 3600) * timeNow) + 15 + 273
        evolve.timeEvolve(pile, dt, ambientT)
        timeNow += dt
        #output = ''
        #if(i>40 and i<75 and i%2==0):

        if (i % log_step == 0):
            time_stamps.append(i * dt / 3600)
            t = interiorAverage(pile.meshTemp, pile.topEdgeOfZ)
            o = interiorAverage(pile.meshO2, pile.topEdgeOfZ)
            b = interiorAverage(pile.meshX, pile.topEdgeOfZ)
            #t = pile.meshTemp[pile.meshTemp.shape[0]//2, pile.topEdgeOfY//2]
            #o = pile.meshO2[pile.meshO2.shape[0]//2, pile.topEdgeOfY//2]
            #b = pile.meshX[pile.meshX.shape[0]//2, pile.topEdgeOfY//2]
            ATemp.append(ambientT)
            Temp.append(t)

            Oxygen.append(o)
            Bacteria.append(b)
            Mass.append(pile.mass)

            plotTemp(pile,
                     i,
                     int(Lx / dx) // 2,
                     filename,
                     dt,
                     time_stamps,
                     Temp,
                     ATemp,
                     start=0)
            plotOxygen(pile,
                       i,
                       int(Lx / dx) // 2,
                       filename,
                       dt,
                       time_stamps,
                       Oxygen,
                       0.272,
                       start=0)
            plotBacteria(pile,
                         i,
                         int(Lx / dx) // 2,
                         filename,
                         dt,
                         time_stamps,
                         Bacteria,
                         start=0)

        if (i % (log_step * 4) == 0):
            print("%.4f%%,%f,%f,%f, %f, %f, %f, %f" %
                  (pile.mass / initialMass * 100, i * dt / 3600, pile.height,
                   ambientT, t, o, b, pile.mass))
            plt.close('all')
            if (pile.mass * pile.height < 0):
                break

    #print (pile.meshTemp)
    #pile.saveFields()

    #https://stackoverflow.com/questions/23876588/matplotlib-colorbar-in-each-subplot
    plotTemp(pile,
             steps,
             int(Lx / dx) // 2,
             filename,
             dt,
             time_stamps,
             Temp,
             ATemp,
             start=0)
    plotOxygen(pile,
               steps,
               int(Lx / dx) // 2,
               filename,
               dt,
               time_stamps,
               Oxygen,
               0.272,
               start=0)
    plotBacteria(pile,
                 steps,
                 int(Lx / dx) // 2,
                 filename,
                 dt,
                 time_stamps,
                 Bacteria,
                 start=0)

    fig = plt.figure(figsize=(16, 12))
    plt.scatter(time_stamps, Mass)
    plt.title("Remaining Mass: %f%%" % (pile.mass / initialMass * 100))
    plt.xlabel("time (min)")
    fig.savefig('%s-Mass-%d-%d-%d-ave.png' %
                (filename, start, start + steps, dt),
                transparent=True)
Beispiel #7
0
 def transfer(self, card, pile):
     Pile.transfer(self, card, pile)
     self.card_taken(card)
Beispiel #8
0
 def __init__(self, initial_size=13):
     Pile.__init__(self)
     self.initial_size = initial_size
Beispiel #9
0
from Utils import *
from Card import Card
from Pile import Pile
from Player import Player

Paul = Player("Dreadful")
GamePile = Pile()
GamePile.Populate()

Paul.DealHand(GamePile)
Paul.AddToPile(GamePile.Deal(25))

Output(Paul)
Output("")
Output(GamePile)
Beispiel #10
0
	def __init__(self, n):
		self.__name = n
		self.__playPile = Pile()
		self.__wonPile = Pile()
""" This model represents a basic sandpile simulation, as described by Bak """

from Pile import Pile

if __name__ == '__main__':
    pile = Pile(5)

    # Given pile ICs
    cols = [[1, 2, 0, 2, 3], [2, 3, 2, 3, 0], [1, 2, 3, 3, 2], [3, 1, 3, 2, 1],
            [0, 2, 2, 1, 2]]

    pile.set_init_cond(cols)
    pile.add_grain(2, 2)
    print(pile)
    print(pile.get_freq_dist())
    print('Done')
Beispiel #12
0
""" This model represents a basic sandpile simulation with rounds of random grain placement """

import random
from Pile import Pile

if __name__ == '__main__':
    pile = Pile(5)

    for i in range(1000):
        x_pos = random.randint(0, 4)
        y_pos = random.randint(0, 4)
        pile.add_grain(x_pos, y_pos)

    print(pile)
    print(pile.get_freq_dist())
    print('Done')
Beispiel #13
0
 def __init__(self):
     Pile.__init__(self)
Beispiel #14
0
from PlayerHand import PlayerHand
import random

pygame.init()

size = width, height = 1200, 800
black = 0, 0, 0
felt = 66, 150, 180

game_title = "Arnason's Hand & Foot Canasta"

display = pygame.display
display.set_caption(game_title)
screen = display.set_mode(size)

cards_pile = Pile()
cards_pile.generate_multiple_decks('load_cards.nsv', pygame.image, 6)
card_width = cards_pile.get_pile()[0].get_rectangle().width
cards_pile.change_pile_position(width / 2 - card_width / 2 - 5, height / 2,
                                True)

card = cards_pile.get_pile()[1]
card.flip_card_over()
cards_pile.move_card(card, width / 2 + card_width / 2 + 5, height / 2)

clicked_card = 0
flag = 0
clock = pygame.time.Clock()

player1_hand = PlayerHand()
player1_hand.deal_hand_and_foot(cards_pile)
Beispiel #15
0
 def __init__(self, Name):
     self.Name = Name
     self.Hand = Pile()
     self.Pile = Pile()
Beispiel #16
0
class Player:
	def __init__(self, n):
		self.__name = n
		self.__playPile = Pile()
		self.__wonPile = Pile()
	def playCard(self):
		if(self.__playPile.getSize() == 0): self.useWonPile()
		if(self.__playPile.getSize() > 0): return self.__playPile.nextCard()
		return None
	def getName(self):
		return self.__name
	def collectCard(self, c):
		self.__wonPile.addCard(c)
	def collectCards(self, p):
		self.__wonPile.addCards(p)
	def useWonPile(self):
		self.__playPile.clear()
		self.__playPile.addCards(self.__wonPile)
		self.__wonPile.clear()
	def numCards(self):
		return self.__playPile.getSize() + self.__wonPile.getSize()
	
	def display(self):
		print(self.__name)
Beispiel #17
0
from Observer import Observer
from Board import Board
from StockPile import StockPile
from Pile import Pile
from Event import *

observer = Observer([])
board = Board(
    StockPile([]).newPile(5),
    StockPile([]).newPile(5), Pile([]), Pile([]), Pile([]), Pile([]))
board = board.setup()

while 1:
    ## Add

    observer = observer.registerObserver(Move(1, 1, 1))
    observer = observer.registerObserver(Spit(1))
    observer = observer.registerObserver(Bored())
    temp = observer.getObservers()

    for i in temp:

        if isinstance(i, Move):
            board = board.move(i.getStockPile(), i.getStockPileNum(),
                               i.getSpitPile())
            observer = observer.unregisterOberserver(i)

        elif (isinstance(i, Bored)):
            board = board.bored()
            observer = observer.unregisterOberserver(i)
Beispiel #18
0
 def calibrate(self):
     """ Prepare cards for display. """
     Pile.calibrate(self)
     self.cards.top_card().face_up()