예제 #1
0
def test_add_to_full_column():
    game = Game()

    # Test adding to a full column
    game.add(0, 1)
    game.add(0, 2)
    game.add(0, 1)
    game.add(0, 2)
    game.add(0, 1)
    game.add(0, 2)
    assert game.add(0, 1) == False
예제 #2
0
def test_horizontal_win():
    game = Game()

    moves = [0, 0, 1, 1, 2, 2, 3, 3]

    for move in moves:
        game.add(move, game.turn + 1)
        assert game.check_win(game.turn + 1) == False
        game.turn = not game.turn

    # winning move
    game.add(4, game.turn + 1)

    # Player one should win
    assert game.check_win(1) == True
예제 #3
0
def test_vertical_win():
    game = Game()

    moves = [0, 1, 0, 1, 0, 1, 0, 1]

    for move in moves:
        game.add(move, game.turn + 1)
        assert game.check_win(game.turn + 1) == False
        game.turn = not game.turn

    # winning move
    game.add(0, game.turn + 1)

    # Player one should win
    assert game.check_win(1) == True
예제 #4
0
def test_p2_win():
    game = Game()

    moves = [0, 1, 0, 1, 0, 1, 0, 1, 2]

    for move in moves:
        game.add(move, game.turn + 1)
        assert game.check_win(game.turn + 1) == False
        game.turn = not game.turn

    # winning move
    game.add(1, game.turn + 1)

    # Player two should win
    assert game.check_win(2) == True
def main():
	a = MetaServerServer('localhost')

	g = Game('testing!')
	g.updateRequired({'key': 'abc', 'tp': '0.3', 'server': 'bazillion!', 'sertype': 'none!', 'rule':'Testing', 'rulever': '0.0.1'})
	g.updateOptional({'admin': 'abc@peanut!', 'cmt':'Hello!'})
	g.addLocation('tp+http', ('localhost', '127.0.0.1', 6923))

	a.GameAdd(g)

	a.run()
예제 #6
0
def test_add_to_each_column():
    game = Game()

    # Test adding to each column
    assert game.add(0, 1) == True
    assert game.add(1, 1) == True
    assert game.add(2, 1) == True
    assert game.add(3, 1) == True
    assert game.add(4, 1) == True
    assert game.add(5, 1) == True
    assert game.add(6, 1) == True
    assert game.add(7, 1) == True
    assert game.add(8, 1) == True
예제 #7
0
def test_draw():
    game = Game()

    moves = [
        0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 2, 3, 2, 3, 2, 3, 3, 2, 3, 2, 3, 2,
        4, 5, 4, 5, 4, 5, 5, 4, 5, 4, 5, 4, 6, 7, 6, 7, 6, 7, 7, 6, 7, 6, 7, 6,
        8, 8, 8, 8, 8, 8
    ]

    for move in moves:
        game.add(move, game.turn + 1)
        assert game.check_win(game.turn + 1) == False
        game.turn = not game.turn

    # No more moves available
    assert game.add(0, game.turn + 1) == False

    # No player should win
    assert game.check_win(1) == False
    assert game.check_win(2) == False

    assert game.check_draw() == True
예제 #8
0
def test_diagonal_forward_win():
    game = Game()

    moves = [0, 1, 1, 2, 2, 3, 2, 3, 4, 3, 4, 4, 3, 4]

    for move in moves:
        game.add(move, game.turn + 1)
        assert game.check_win(game.turn + 1) == False
        game.turn = not game.turn

    # winning move
    game.add(4, game.turn + 1)
    """ final board
	[ ][ ][ ][ ][ ][ ][ ][ ][ ]
	[ ][ ][ ][ ][x][ ][ ][ ][ ]
	[ ][ ][ ][x][o][ ][ ][ ][ ]
	[ ][ ][x][o][x][ ][ ][ ][ ]
	[ ][x][x][o][o][ ][ ][ ][ ]
	[x][o][o][o][x][ ][ ][ ][ ]
	"""

    # Player one should win
    assert game.check_win(1) == True
예제 #9
0
def test_diagonal_back_win():
    game = Game()

    moves = [4, 4, 4, 4, 4, 5, 8, 7, 7, 6, 6, 5, 6, 5]

    for move in moves:
        game.add(move, game.turn + 1)
        assert game.check_win(game.turn + 1) == False
        game.turn = not game.turn

    # winning move
    game.add(5, game.turn + 1)
    """ final board
	[ ][ ][ ][ ][ ][ ][ ][ ][ ]
	[ ][ ][ ][ ][x][ ][ ][ ][ ]
	[ ][ ][ ][ ][o][x][ ][ ][ ]
	[ ][ ][ ][ ][x][o][x][ ][ ]
	[ ][ ][ ][ ][o][o][x][x][ ]
	[ ][ ][ ][ ][x][o][o][o][x]
	"""

    # Player one should win
    assert game.check_win(1) == True
예제 #10
0
from keras.models import Sequential
from keras.layers import *
from keras.optimizers import *
from qlearning4k import Agent

#------------------------------------
from server import Game
#------------------------------------

from keras import backend as K
K.set_image_dim_ordering('th')

grid_size = 21
nb_frames = 1
nb_actions = 5

model = Sequential()
model.add(Conv2D(16, (3, 3), activation='relu', input_shape=(nb_frames, grid_size, grid_size, 3)))
model.add(Conv2D(32, (4, 4), activation='relu'))
model.add(Flatten())
model.add(Dense(256, activation='relu'))
model.add(Dense(nb_actions))
model.compile(RMSprop(), 'MSE')

#------------------------------------
game = Game()
#------------------------------------

agent = Agent(model=model, memory_size=-1, nb_frames=nb_frames)
agent.train(game, batch_size=1, nb_epoch=10000, gamma=0.8)
agent.play(game)
예제 #11
0
def test_add_bad_player_number():
    game = Game()

    # Test vaild player number (can only be 1 or 2)
    assert game.add(0, 0) == False
    assert game.add(0, 3) == False
예제 #12
0
def test_add_bad_column_range():
    game = Game()

    # Test out of out of bounds turn (0-8)
    assert game.add(9, 1) == False
    assert game.add(-1, 1) == False