Ejemplo n.º 1
0
def assert_move_conflict():
    b = Board()
    p1p1 = Position(4, 2)
    p2p1 = Position(4, 4)

    p1p2 = Position(5, 2)
    p1p3 = Position(6, 1)
    p2p2 = Position(5, 4)

    b.put(p1p1, Soldier(player_1))
    b.put(p2p1, Soldier(player_2))
    b.put(p1p2, Soldier(player_1))
    b.put(p1p3, Rider(player_1))
    b.put(p2p2, Soldier(player_2))
    g = Game(b)
    g.replenish(100)

    g = g.make_move([
        PlayerMove.from_literal(player_2, "5554 6564"),
        PlayerMove.from_literal(player_1, "5354 6364 7264")
    ])

    assert (g.board.at(p1p1) is None)
    assert (g.board.at(p2p1) is None)
    assert (g.board.at(p1p2) is None)
    assert (g.board.at(p1p3) is not None)
    assert (g.board.at(p2p2) is None)
    assert (g.board.at(Position(5, 3)).owner == player_1)
Ejemplo n.º 2
0
def assert_attack_defend():
    b = Board()
    p2u1 = Position.from_literal('55')
    p2u2 = Position.from_literal('66')
    p2u3 = Position.from_literal('61')
    #p2u4 = Position.from_literal('65')

    p1u1 = Position.from_literal('54')
    p1u2 = Position.from_literal('53')
    p1u3 = Position.from_literal('62')
    p1u4 = Position.from_literal('67')
    p1u5 = Position.from_literal('56')

    b.put(p2u1, Soldier(player_2))
    b.put(p2u2, Rider(player_2, flip_skillset=True))
    b.put(p2u3, Soldier(player_2))
    #b.put(p2u4, Barbarian(player_2, flip_skillset=True)))

    b.put(p1u1, Rider(player_1))
    b.put(p1u2, Soldier(player_1))
    b.put(p1u3, Rider(player_1))
    b.put(p1u4, Soldier(player_1))
    b.put(p1u5, Soldier(player_1))

    g = Game(b)
    g.replenish(100)

    # renderer.show_canvas(
    #     paint.get_painted_canvas(
    #         g, {player_1:'a', player_2:'b'}, player_1))

    g = g.make_move([
        PlayerMove.from_literal(player_2, "5554 6654 6162"),
        PlayerMove.from_literal(player_1, "5354 6254 6766 5655 5446")
    ])

    # for clash_brief in g.round_brief.clash_briefs:
    #     print(clash_brief.brief())

    # for battle_brief in g.round_brief.battle_briefs:
    #     print(battle_brief.brief())

    assert (g.board.at(p2u1).owner == player_1)
    assert (g.board.at(p2u2).owner == player_1)
    assert (g.board.at(p2u3) is None)

    assert (g.board.at(p1u1) is None)
    assert (g.board.at(p1u2).owner == player_1)
    assert (g.board.at(p1u3).owner == player_2)
    assert (g.board.at(p1u4) is None)
    assert (g.board.at(p1u5) is None)

    assert (g.board.at(Position.from_literal('46')).owner == player_1)
Ejemplo n.º 3
0
def assert_input():
    b = Board()
    b.put(Position(4, 3), Soldier(player_1))
    b.put(Position(4, 2), Soldier(player_1))
    b.put(Position(4, 4), Soldier(player_2))
    b.put(Position(4, 5), Soldier(player_2))
    g = Game(b)
    g.replenish(100)

    player_action = g.validate_player_move(PlayerMove.from_literal(player_2, "4443 4546"))
    assert(str(player_action) == '55->54(ATK),56->57(MOV)')
    player_action = g.validate_player_move(PlayerMove.from_literal(player_1, "4342 4252"))
    assert(str(player_action) == '54->53(DEF),53->63(UPG)')
Ejemplo n.º 4
0
def assert_clash():
    b = Board()
    p1p = Position(4, 3)
    p2p = Position(4, 4)
    b.put(p1p, Soldier(player_1))
    b.put(p2p, Soldier(player_2))
    g = Game(b)
    g.replenish(100)

    g = g.make_move([
        PlayerMove.from_literal(player_2, "5554"),
        PlayerMove.from_literal(player_1, "5455")
    ])

    assert (g.board.at(p1p) is None)
    assert (g.board.at(p2p) is None)
Ejemplo n.º 5
0
def assert_buffs():
    b = Board()

    b.put(Position.from_literal('55'), make_perfect(Lancer(player_1, SkillSet())))
    b.put(Position.from_literal('66'), make_perfect(Knight(player_1, SkillSet())))
    b.put(Position.from_literal('46'), make_perfect(Knight(player_1, SkillSet())))
    b.put(Position.from_literal('68'), make_perfect(Warrior(player_2, SkillSet())))
    b.put(Position.from_literal('78'), make_perfect(Spearman(player_1, SkillSet())))
    b.put(Position.from_literal('88'), make_perfect(Spearman(player_1, SkillSet())))
    b.put(Position.from_literal('53'), make_perfect(Soldier(player_1)))
    b.put(Position.from_literal('52'), make_perfect(Soldier(player_2)))
    b.put(Position.from_literal('59'), Swordsman(player_1, SkillSet()))

    g = Game(b)
    g = g.make_move([
        PlayerMove.from_literal(player_1, "4241 4442 5563 4857 6757 7757"),
        PlayerMove.from_literal(player_2, "")])

    assert(g.supply[player_1] == 29) # 40 - 16 + 5
Ejemplo n.º 6
0
    def get_random_player_move(self, player):
        move_list = []
        while random.randint(0, 12) != 0:
            if random.randint(0, 8) == 0:
                recruit_position = Position(
                    random.randint(0, board_size_x - 1),
                    rule.spawn_row[player])
                move = Move(recruit_position, recruit_position)
            else:
                move = random.choice(
                    rule.all_valid_moves(self.board, player, True))
            try:
                self.validate_player_move(
                    PlayerMove(player, move_list + [move]))
                move_list.append(move)
            except rule.InvalidMoveException:
                break

        print(move_list)
        return PlayerMove(player, move_list)
Ejemplo n.º 7
0
def assert_attack_defend():
    b = Board()
    p2u1 = Position.from_literal('55')
    p2u2 = Position.from_literal('66')
    p2u3 = Position.from_literal('61')

    p1u1 = Position.from_literal('54')
    p1u2 = Position.from_literal('53')
    p1u3 = Position.from_literal('62')
    p1u4 = Position.from_literal('67')
    p1u5 = Position.from_literal('56')

    b.put(p2u1, Soldier(player_2))
    b.put(p2u2, make_perfect(Rider(player_2)))
    b.put(p2u3, Soldier(player_2))

    b.put(p1u1, make_perfect(Rider(player_1)))
    b.put(p1u2, Soldier(player_1))
    b.put(p1u3, make_perfect(Rider(player_1)))
    b.put(p1u4, Soldier(player_1))
    b.put(p1u5, Soldier(player_1))

    g = Game(b)
    g.replenish(100)

    g = g.make_move([
        PlayerMove.from_literal(player_2, "4443 5543 5051"),
        PlayerMove.from_literal(player_1, "4243 5143 5655 4544 4335")])

    assert(g.board.at(p2u1).owner == player_1)
    assert(g.board.at(p2u2).owner == player_1)
    assert(g.board.at(p2u3) is None)

    assert(g.board.at(p1u1) is None)
    assert(g.board.at(p1u2).owner == player_1)
    assert(g.board.at(p1u3).owner == player_2)
    assert(g.board.at(p1u4) is None)
    assert(g.board.at(p1u5) is None)

    assert(g.board.at(Position.from_literal('46')).owner == player_1)
Ejemplo n.º 8
0
def assert_clash():
    b = Board()
    p1p = Position(4, 3)
    p1p2 = Position(5, 6)
    p2p = Position(4, 4)
    s = Spearman(player_1, SkillSet())
    s.endow(Skill(PositionDelta(0, 1)))
    b.put(p1p, s)
    r = Rider(player_1)
    r.endow(Skill(PositionDelta(-1, -2)))
    b.put(p1p2, r)
    b.put(p2p, Soldier(player_2))
    g = Game(b)
    g.replenish(100)

    g = g.make_move([
        PlayerMove.from_literal(player_2, "4443"),
        PlayerMove.from_literal(player_1, "5644 4344")])

    assert(type(g.martyr_list[0].board_unit.unit) == Soldier)
    assert(type(g.board.at(p1p)) == Spearman)
    assert(type(g.board.at(p2p)) == Rider)
Ejemplo n.º 9
0
def assert_invalid_input():
    b = Board()

    b.put(Position(4, 3), Soldier(player_1))
    b.put(Position(4, 4), Soldier(player_2))

    g = Game(b)
    g.replenish(100)

    try:
        g.validate_player_move(PlayerMove.from_literal(player_2, "5554 5565"))
    except rule.InvalidMoveException:
        pass
    else:
        assert (None)
Ejemplo n.º 10
0
def read_player_move_online(game, player, name, session_id):
    while True:
        i = input(f"[x:exit r:rollback {name}]: ")
        if i == op_exit:
            raise ExitCommand
        if i == op_rollback:
            net.rollback_game(session_id)
            raise RollbackCommand

        try:
            player_move = PlayerMove.from_literal(player, i)
        except:
            prompt("invalid input")
            continue

        try:
            game.validate_player_move(player_move)
        except rule.InvalidMoveException as e:
            prompt(e)
            continue

        return player_move
Ejemplo n.º 11
0
def read_player_move_hotseat(game, player, name):
    if player_autoplay[player]:
        return game.get_random_player_move(player)
    while True:
        i = input(f"[x:exit a:autoplay {name}]: ")
        if i == op_exit:
            raise ExitCommand
        if i == op_toggle_auto:
            player_autoplay[player] = True
            return game.get_random_player_move(player)

        try:
            player_move = PlayerMove.from_literal(player, i)
        except:
            prompt("invalid input")
            continue

        try:
            game.validate_player_move(player_move)
        except rule.InvalidMoveException as e:
            prompt(e)
            continue

        return player_move
Ejemplo n.º 12
0
def assert_recall():
    b = Board()

    b.put(Position.from_literal('55'), King(player_1))
    b.put(Position.from_literal('57'), make_perfect(Soldier(player_2, SkillSet())))

    b.put(Position.from_literal('88'), make_perfect(Soldier(player_2, SkillSet())))
    b.put(Position.from_literal('89'), make_perfect(Lancer(player_1, SkillSet())))

    b.put(Position.from_literal('11'), make_perfect(Lancer(player_1, SkillSet())))
    
    g = Game(b)
    try:
        g = g.make_move([
            PlayerMove.from_literal(player_1, "5478"),
            PlayerMove.from_literal(player_2, "")])
    except:
        pass
    else:
        raise Exception()

    try:
        g = g.make_move([
            PlayerMove.from_literal(player_1, "4500"),
            PlayerMove.from_literal(player_2, "")])
    except:
        pass
    else:
        raise Exception()

    g = g.make_move([
        PlayerMove.from_literal(player_1, "5400"),
        PlayerMove.from_literal(player_2, "")])
    
    assert(g.board.at(Position.from_literal('11')) is None)
    assert(g.board.at(Position.from_literal('65')).owner == player_1)