예제 #1
0
def homepage():
    win = GraphWin("Chess", 400, 400)
    win.setCoords(0, 0, 400, 400)
    win.setBackground("systemhighlight")
    ext = exitbutton(win)

    game = Button(win, Point(325, 75), 100, 50, "TBD")
    game1 = Button(win, Point(325, 135), 100, 50, "Checkers")
    game2 = Button(win, Point(325, 195), 100, 50, "Chess")
    game3 = Button(win, Point(325, 255), 100, 50, "Tictactoe")
    game4 = Button(win, Point(325, 315), 100, 50, "Hangman")
    game4.activate("red")
    game3.activate("orange")
    game2.deactivate()
    game1.deactivate()
    game.deactivate()
    buttonlist = [game, game1, game2, game3, game4, ext]
    while 1 == 1:
        p = win.getMouse()
        if buttonlist[5].clicked(p) == True:
            win.close()
            quit()
        elif buttonlist[4].clicked(p) == True:
            win.close()
            hangman.main()
        elif buttonlist[3].clicked(p) == True:
            win.close()
            Tictactoe.ticmain()
        elif buttonlist[2].clicked(p) == True:
            win.close()
        elif buttonlist[1].clicked(p) == True:
            win.close()
        elif buttonlist[0].clicked(p) == True:
            win.close()
예제 #2
0
def win_draw_counter(grid, player):
    win_counter = 0
    draw_counter = 0
    ct = comp_gametree(grid, player)
    flatten_ct = ttt.chop(3, (ttt.chop(3, flat(ct))))
    for i in range(len(flatten_ct)):
        if ttt.won(flatten_ct[i]):
            win_counter += 1
        elif ttt.full(flatten_ct[i]):
            draw_counter += 1
    return (win_counter, draw_counter)
예제 #3
0
def comp_gametree(grid, player):
    if ttt.full(grid):
        possible_moves = []
    elif ttt.won(grid):
        possible_moves = []
    else:
        if player == 'O':
            possible_moves = ttt.moves(grid, player)
        elif player == 'X':
            possible_moves = [
                ttt.move(grid, (ttt.show_diff_pos(grid)) - 1, player)
            ]
    leave = list(
        map(lambda x: comp_gametree(x, ttt.next(player)), possible_moves))
    result = [grid] + [leave]
    return result
예제 #4
0
def play(b, X_def, O_def, number):
    victory = 0
    p = 0
    for i in range(1, number + 1):
        p += 1
        r = genericGame(Tictactoe.Board(), X_def, O_def, False)
        victory += r

        if (p % 1 == 0 or i == number):
            os.system("clear")
            print(17 * '*')
            if (r == 1):
                print("%.2f" % (i / number * 100) + " % -> " +
                      bcolors.OKGREEN + "%.2f" % (victory / i * 100) +
                      bcolors.ENDC)

            elif (r == 0):
                print("%.2f" % (i / number * 100) + " % -> " + bcolors.OKBLUE +
                      "%.2f" % (victory / i * 100) + bcolors.ENDC)

            else:
                print("%.2f" % (i / number * 100) + " % -> " + bcolors.FAIL +
                      "%.2f" % (victory / i * 100) + bcolors.ENDC)
            print(17 * '*')
예제 #5
0
# Import all files from
# tkinter and overwrite
# all the tkinter files
# by tkinter.ttk
from tkinter import *
from tkinter.ttk import *
import Tictactoe

Tic = Tictactoe.Tictactoe()

peice = ' '


# function to be called when
# keyboard buttons are pressed
def show(event):
    Tic.printArr()


def place1(event):
    Tic.place(0, 0)


def place2(event):
    Tic.place(1, 0)


def place3(event):
    Tic.place(2, 0)

예제 #6
0
파일: bot.py 프로젝트: Dabanana/Banana-Bot
def on_message(message):
	if message.author == client.user:
		return

	if message.content.startswith('#test'):
		yield from client.send_message(message.channel, "This is a f*****g test")

	if message.content.startswith('#frank'):
		yield from client.send_message(message.channel, "Hey I'm Frank. Would you like to know my opinion?")
		opinions = ["Hey, I agree with your opinion.", "I'm f*****g triggered!", "Hey, your opinion's stupid"]
		msg = yield from client.wait_for_message(timeout = 10, author = message.author)
		if msg is None:
			yield from client.send_message(message.channel, "Wow... I really wanted to share my opinion")
			return
		if msg.content == "yes":
			num = random.randint(0,2)
			yield from client.send_message(message.channel, opinions[num])
		elif msg.content == "no":
			yield from client.send_message(message.channel, "Um. Wu")
		elif msg.content == "wu":
			while True:
				yield from client.send_message(message.channel, "Yo. Wu")
				msg = yield from client.wait_for_message(timeout = 10, author = message.author,content = "wu") 
				if msg is None:
					yield from client.send_message(message.channel, "Wu!")
					return

	if message.content.startswith('#choose '):
		msg = message.content[len('#choose'):].strip()
		if msg == "":
			yield from client.send_message(message.channel, "Give me some choices man!")
			return
		choices = msg.split(",")
		xs = len(choices)
		if xs == 1:
			yield from client.send_message(message.channel, "You only gave me one choice, c**t.")
			return
		num = random.randint(0,xs)
		yield from client.send_message(message.channel, "I choose {0}".format(choices[num]))

	if message.content.startswith('#kierannudes'):
		yield from client.send_file(message.channel, "C://bananabot//kieran.jpg", filename = "kieran.jpg", content = "I don't have nudes but I have...")

	if message.content.startswith('#shutdown'):
		yield from client.send_message(message.channel, "Shutting down...")
		yield from client.logout()

	if message.content.startswith('#tictactoe'):
		t = Tictactoe.Tictactoe()
		yield from client.send_message(message.channel, t)
		while True:
			message = yield from client.wait_for_message()
			if message.content.startswith('#killttc'):
				yield from client.send_message(message.channel, "Tictactoe game is dead.")
				return
			if message.content.startswith('#naught'):
				coord = message.content.strip("#naught ")
				row = int(coord[2])
				column = int(coord[0])
				yield from client.send_message(message.channel, t.naught(column,row))
				yield from client.send_message(message.channel, t.check())
			elif message.content.startswith('#cross'):
				coord = message.content[len('#cross'):].strip()
				row = int(coord[2])
				column = int(coord[0])
				yield from client.send_message(message.channel, t.cross(column,row))
				yield from client.send_message(message.channel, t.check())
			if t.win != 0:
				return

	if message.content.startswith('#bb'):
		question = message.content.strip('#bb ')
		answer = cleverbot_client.ask(question)
		yield from client.send_message(message.channel, answer)

	if "harambe" in message.content.lower():
		yield from client.send_message(message.channel, "RIP")

	if "banana" in message.content.lower():
		yield from client.send_message(message.channel, ":Banana:")

	if message.content.startswith("#psr"):
		msg = message.content.strip("psr# ")
		psr = [":fist:", ":v:", ":raised_hand:"]
		num = random.randint(0,2)
		ans = psr[num]
		if num - 1 == -1:
			win = psr[2]
		else:
			win = psr[num - 1]
		if num + 1 == 3:
			lose = psr[0]
		else:
			lose = psr[num + 1]
		yield from client.send_message(message.channel, ans)
		if ans in msg:
			yield from client.send_message(message.channel, "It's a draw!")
			return
		elif win in msg:
			yield from client.send_message(message.channel, "You win!")
			return
		elif lose in msg:
			yield from client.send_message(message.channel, "You lose!")
			return
예제 #7
0
from time import sleep

import Tictactoe
import Tablero
import Jugador
import QLearning

ai = QLearning.QLearning()
ai2 = QLearning.QLearning()

jugador1 = Jugador.Jugador("player1", 'X', ai)
jugador2 = Jugador.Jugador("player2", 'O', None)

jugadores = []
jugadores.append(jugador1)
jugadores.append(jugador2)

tablero = Tablero.Tablero()
game = Tictactoe.tictactoe(tablero, jugadores)

game.encender()

#while True:
#    game.new_game()
#    if game.iterations == 3:
#        game.new_game(t="q")
#        break
                break
            
        elif( niveau ==1):
            tmp = rechercheStrategieGagnanteAmelioree(b,1-niveau)
            if(tmp == 1):
                break
            if(tmp == -1 or tmp == 0):
                res = res or False
        
        b.pop()
    return res




board = Tictactoe.Board()
# print(board)

### Deroulement d'une partie aléatoire
# deroulementRandom(board)



# print("Apres le match, chaque coup est défait (grâce aux pop()): on retrouve le plateau de départ :")
# print(board)

print(rechercheStrategieGagnante(board,0))

print(nbNoeuds)