Esempio n. 1
0
    def __init__(self, windowWidth, windowHeight, title):
        pygame.init()
        self.disp = pygame.display.set_mode((windowWidth, windowHeight))
        self.windowWidth = windowWidth
        self.windowHeight = windowHeight
        pygame.display.set_caption(title)
        #setup a board
        self.board = board(self.disp)
        #create a snake
        self.snake = snake(self.disp, ((windowWidth / 2) // constants.snake_size)*constants.snake_size, ((windowHeight / 2) // constants.snake_size)*constants.snake_size)
        #create a clock to manage fps
        self.clock = pygame.time.Clock()
        #create an apple
        self.apple = apple(self.disp)

        self.foodEaten = False

        self.isOpen = True


        #create userevents for movement
        self.inputUP = pygame.event.Event(pygame.USEREVENT +1)
        self.inputDOWN = pygame.event.Event(pygame.USEREVENT +2)
        self.inputLEFT = pygame.event.Event(pygame.USEREVENT + 3)
        self.inputRIGHT = pygame.event.Event(pygame.USEREVENT + 4)

        self.step(2) # first event fixed for now
Esempio n. 2
0
 def __init__(self):
     self.board = board(np.tile(' ', (7, 7)))
     Minimax.__init__(self)
     self.fen = Tk()
     self.COTE = 350
     self.case = 50
     self.isMinMax = False
     self.can=Canvas(self.fen,bg="white", height=self.COTE, width=self.COTE)
     self.can.pack()
     self.var = IntVar()
     def get_int(coup):
         self.var.set(random.randint(1,9999))
         print(self.var.get( ))
         self.coup = coup
         print(coup)
     canvButton = Canvas(self.fen,bg="white", height=self.case, width=self.COTE)
     canvButton.pack()
     self.bout1 = Button(canvButton, text='1',width=5, command = lambda:get_int(1))
     self.bout1.grid(row=0)
     print("bout1")
     self.bout2 = Button(canvButton, text='2', width=5, command=lambda:get_int(2)).grid(row=0, column=1)
     self.bout2 = Button(canvButton, text='3', width=5, command=lambda:get_int(3)).grid(row=0, column=2)
     self.bout2 = Button(canvButton, text='4', width=5, command=lambda:get_int(4)).grid(row=0, column=3)
     self.bout2 = Button(canvButton, text='5', width=5, command=lambda:get_int(5)).grid(row=0, column=4)
     self.bout2 = Button(canvButton, text='6', width=5, command=lambda:get_int(6)).grid(row=0, column=5)
     self.bout2 = Button(canvButton, text='7', width=5, command=lambda:get_int(7)).grid(row=0, column=7)
     self.init_board_GUI()
     self.partie()
     self.fen.mainloop()
Esempio n. 3
0
    def __init__(self,parent = None):
        super(MainWindow,self).__init__(parent)
        self.setupUi(self)
        self.LengthEdit = lengthEdit(self)
        if self.LengthEdit.exec_():
            self.length = int(self.LengthEdit.comboBox.currentText().split('*')[0])
            if self.LengthEdit.timeBox.currentText().isdigit():
                self.timeLimit = int(self.LengthEdit.timeBox.currentText())
            else:
                self.timeLimit = float('inf')
        else:
            exit(0)

        self.cnt = 0
        self.board = board(self.length+1)
        self.steps = self.board.steps
        self.colors = ['black', 'white']
        self.initWidgets()
        self.lastStep = (None, None)
        self.timer = QtCore.QTimer(self)
        if self.timeLimit < 60:
            self.timer = QtCore.QTimer(self)
            self.timer.timeout.connect(self.timeOut)
            self.timer.start(1000)

        file = "src\\down.mp3"
        music = QMediaContent(QtCore.QUrl.fromLocalFile(file))
        self.player = QMediaPlayer()
        self.player.setMedia(music)

        self.replayButton.clicked.connect(self.replay)
        self.ExitButton.clicked.connect(self.close)
        self.regretButton.clicked.connect(self.regret)
        self.surrenderButton.clicked.connect(self.surrender)
Esempio n. 4
0
def main():

    clock = pygame.time.Clock()
    run = True
    p1Time = 900
    p2Time = 900
    
    
    piece_display = board(8,8)

    while run:
        
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False
                quit()
                pygame.quit()
            
            if event.type == pygame.MOUSEBUTTONUP: 
                    pos = pygame.mouse.get_pos()
                    i, j = click(pos)
                    piece_display.select(i,j,piece_display.turn)
                    piece_display.update_moves()
                    print(i,j,piece_display.turn)
                    
                   

        win.blit(board_img, (0, 0))
        
        #displaying the pieces
        piece_display.draw(win,piece_display.turn)
        
        pygame.display.update()
  
    menu_screen(win)
Esempio n. 5
0
def main_window():
	DROP_EVENT = USEREVENT + 1
	
	
	lost = False
	pygame.init()
	fps_clock = pygame.time.Clock()
	main_win = pygame.display.set_mode((WIDTH, HEIGHT))
	new_board = board(main_win, (HEIGHT/BLOCK_SIZE), (WIDTH/BLOCK_SIZE), BLUE, BLACK)
	current_shape = tetras(main_win, 30, 30, COLOURS[random.randrange(5)], BLACK)
	
	pygame.time.set_timer(DROP_EVENT, 1000) # moves down every second, make this a variable later.
	
	while True:
		
		print "Main Loop starts"
		
		fps_clock.tick(FPS)
		
		for event in pygame.event.get():
			if event.type == QUIT:
				pygame.quit()
				sys.exit()
			elif event.type == KEYDOWN:
				handle_events(current_shape, event.key)
			elif event.type == DROP_EVENT:
				current_shape.move_down()
	
			
		new_board.update(current_shape)
		
		if new_board.collision(current_shape) == False:
			new_board.draw()
		else:
			current_shape = tetras(main_win, 30, 30, COLOURS[random.randrange(5)], BLACK)
			new_board.draw()	
			
		pygame.display.update()
		
		print "Main Loop ends"	
Esempio n. 6
0
    def __init__(self, windowWidth, windowHeight, title):
        pygame.init()
        self.disp = pygame.display.set_mode((windowWidth, windowHeight))
        self.windowWidth = windowWidth
        self.windowHeight = windowHeight
        pygame.display.set_caption(title)
        #setup a board
        self.board = board(self.disp)
        #create a snake
        self.snake = snake(self.disp,
                           ((windowWidth / 2) // constants.snake_size) *
                           constants.snake_size,
                           ((windowHeight / 2) // constants.snake_size) *
                           constants.snake_size)
        #create a clock to manage fps
        self.clock = pygame.time.Clock()
        #create an apple
        self.apple = apple(self.disp)

        self.foodEaten = False

        self.run()
Esempio n. 7
0
from Player import Player
from Board import board

me = Player()
enemy = Player()
board = board()
board.commentary = True

# print(me.hand)

for x in range(14):
    flippedCard = board.flipCard()
    print("Opponent bets: {}".format(enemy.autoBets(flippedCard)))
    me.askBet()
from Queen import queen
from Knight import knight
from Board import board
import pandas as pd
import numpy as np

chess = board(8, 8)
board_size = (8, 8)

data = [['X'] * 8] * 8
df = pd.DataFrame(data)

place_piece = 'Q'
safe_place = chess.copy()
not_safe_place = []
next_place = 1

for pos in safe_place:

    if next_place in range(1, 5):

        safe = True
        veri = []

        if df.iloc[pos[0], pos[1]] == 'X':
            atk_pos = queen(pos[0], pos[1], board_size)

            for danger in atk_pos:
                veri.append(df.iloc[danger[0], danger[1]])

            for piece in veri:
Esempio n. 9
0
	def main(stdscr):
		setCurses(stdscr)
		h, w = stdscr.getmaxyx()
		p1 = player('raf', 10)
		b = board(1)

		if len(sys.argv) > 1:
			seed = int(sys.argv[1])
		else: seed = ''

		random.seed()
		roomSizeIdx = random.randrange(0, len(roomSizes))

		random.seed()
		numRooms = random.randrange(1, 6)
		for i in range(0,  numRooms):
			random.seed()
			roomSizeIdx = random.randrange(0, len(roomSizes))

			originX = random.randrange(0, w - 20)
			originY = random.randrange(0, h - 15)
			origin = (originX, originY)
			b.addRoom(room(roomSizes[roomSizeIdx], stdscr, origin))

		running = True
		while running:

			stdscr.addstr(h-1, int(w/2), '           ') 
			stdscr.addstr(h-1, int(w/2), '(%i, %i)' % (p1.getX(), p1.getY())) 
			stdscr.addstr(h-1, 1, '        ') 
			stdscr.addstr(h-1, 1, 'Health: %i' % (p1.getHealth()))
			stdscr.addstr(h-1, w-10, '        ') 
			stdscr.addstr(h-1, w-10, 'Rooms: %i' % (b.getNumRooms()))
			
			b.printBoard()

			stdscr.move(p1.y, p1.x)
			key = stdscr.getch()

			if key == curses.KEY_UP:
				if p1.y == 0:
					p1.y = 0
				else:
					p1.y -= 1

			elif key == curses.KEY_DOWN:
				if p1.y == h-2:
					p1.y = p1.y
				else:
					p1.y += 1

			elif key == curses.KEY_LEFT:
				if p1.x == 0:
					p1.x = 0
				else:
					p1.x -= 1

			elif key == curses.KEY_RIGHT:
				if p1.x == w-1:
					p1.x = p1.x
				else:
					p1.x += 1

			elif key == ord('q') or key == ord('Q'):
				exit()


			b.updateRooms(p1)
			stdscr.refresh()
Esempio n. 10
0
from __future__ import print_function
from __future__ import division
from Board import board
from computer import computer
from sys import maxsize
from copy import deepcopy

#Board initialization
gameBoard = board(8)

#Player choice variable
playerChoice = ""

#Player array
players = list("012")

currentTile = 1
wilfred = computer(gameBoard)

#Greetings
print("Welcome to Ganji-Ho")

#Game Setup
while True:

    print("-------------------")
    print("Please select game mode.")
    print("Press 1 for Player versus Player")
    print("Press 2 for Player versus AI")
    print("Press 3 for instructions")
Esempio n. 11
0
print contact_rate, recovery_rate

#calculus
quantity_cells_around=int(round(66.0/(MEDIA_DIVULGATION*5+SINGER_POPULARITY*3)))
number_generations_to_be_recovered=int(round((MEDIA_DIVULGATION*4+SINGER_POPULARITY*2)*7/10.0))
number_generations_to_be_infected=int(round(42.0/number_generations_to_be_recovered))

def cell_list():
    lst = []
    for i in xrange(map_size):
    	lst.append([])
        for g in xrange(map_size): 
		lst[i].append((board.map[i][g].location[0]*square_size,board.map[i][g].location[1]*square_size))
    return lst

board = board(map_size, img_alive, img_dead, square_size, number_generations_to_be_recovered, number_generations_to_be_infected, quantity_cells_around, img_recovered, contact_rate, recovery_rate)
board.fill(False)
board.draw(screen)  
tp = 0

#indicates whether the game runs or not
run = False

while done == False:
	milliseconds = clock.tick(60)
	seconds = milliseconds / 1000.0
	tp += milliseconds

	#retrieve user commands
	for event in pygame.event.get():
		if event.type == QUIT: