Example #1
0
    def test_when_no_moves_available(self):
        with self.assertRaisesRegex(ValueError,
                                    'no available moves: xxxoo....'):
            ai.evaluate(Board.fromstring('xxxoo'), 'x')

        with self.assertRaisesRegex(ValueError,
                                    'no available moves: xxxoo....'):
            ai.evaluate(Board.fromstring('xxxoo'), 'o')
Example #2
0
 def test_xeeeoeeee(self):
     self.assertEqual(
         ai.evaluate(Board.fromstring('x...o'), 'x').positions, [(1, 2),
                                                                 (1, 3),
                                                                 (2, 1),
                                                                 (2, 3),
                                                                 (3, 1),
                                                                 (3, 2),
                                                                 (3, 3)])
Example #3
0
 def _convertBoard(self, board):
     outBoard = []
     for r in range(3):
         for c in range(3):
             i = 3 * r + c
             if board[i] == game.Empty:
                 t = '.'
             else:
                 t = board[i].lower()
             outBoard.append(t)
     return Board.fromstring(''.join(outBoard))
Example #4
0
 def test_when_layout_is_empty(self):
     self.assertEqual(str(Board.fromstring()), '.........')
Example #5
0
 def setUp(self):
     self.board = Board.fromstring('x.xo..')
Example #6
0
 def setUp(self):
     self.board = Board.fromstring('x.o.o.x.x')
Example #7
0
 def test_when_layout_is_longer_than_9_characters(self):
     self.assertEqual(str(Board.fromstring('x       oxoxo')), 'x.......o')
Example #8
0
 def test_when_layout_is_non_empty_but_shorter_than_9_characters(self):
     self.assertEqual(str(Board.fromstring('x')), 'x........')
Example #9
0
async def on_message(message):

    if message.content == "z.info":
        tmpembed = discord.Embed(title = "XenoBot", description = "a0.0.1")
        tmpembed.set_thumbnail(url = app.user.avatar_url)
        await message.channel.send(embed = tmpembed)
        return

    elif message.content == "z.help":
        tmpembed = discord.Embed(title = "Minigames", description = f"There're {len(minigames)} minigames!\n\
        `z.play <Minigame Number>` to play minigame!")
        for x in range(len(minigames)):
            tmpembed.add_field(name = f"{x + 1}. {minigames[x][0]}", value = f"`{minigames[x][1]}`")
        await message.channel.send(embed = tmpembed)
        return

    elif message.content == "z.ping":
        tmpembed = discord.Embed(title = "πŸ“ Pong!", description = f"{str(app.latency * 1000)[:6]}ms")
        await message.channel.send(embed = tmpembed)

    elif message.content.startswith("z.play"):
        gamenumber = message.content[7:]
        if gamenumber == "1" or gamenumber == "κ°€μœ„λ°”μœ„λ³΄":
            tmpembed = discord.Embed(title = "πŸ–οΈ κ°€μœ„λ°”μœ„λ³΄", description = "각자 κ°€μœ„ λ˜λŠ” λ°”μœ„ λ˜λŠ” 보λ₯Ό λ‚΄μ„œ μŠΉλΆ€λ₯Ό κ²°μ •ν•˜λŠ” κ²Œμž„μž…λ‹ˆλ‹€. κ°€μœ„λŠ” 보λ₯Ό, λ°”μœ„λŠ” κ°€μœ„λ₯Ό, λ³΄λŠ” 묡을 이길 수 μžˆμŠ΅λ‹ˆλ‹€. 두 λͺ…이 같은 손을 λ‚Ό μ‹œ λΉ„κΉλ‹ˆλ‹€.")
            await message.channel.send(embed = tmpembed)
            tmpembed = discord.Embed(title = "κ°€μœ„, λ°”μœ„, 보 쀑 ν•˜λ‚˜λ₯Ό μ„ νƒν•˜μ„Έμš”")
            main = await message.channel.send(embed = tmpembed)
            await main.add_reaction("✌️")
            await main.add_reaction("✊")
            await main.add_reaction("πŸ–οΈ")
            hands = ["✌️", "✊", "πŸ–οΈ"]
            def check(reaction, user):
                return user == message.author and str(reaction.emoji) in hands
            try:
                reaction, user = await app.wait_for('reaction_add', timeout = 5, check = check)
            except asyncio.TimeoutError:
                tmpembed = discord.Embed(title = "당신은 νŒ¨λ°°ν•˜μ˜€μŠ΅λ‹ˆλ‹€!", description = "μ„ νƒν•˜λŠ” 데 μ‹œκ°„μ΄ λ„ˆλ¬΄ 였래 κ±Έλ ΈμŠ΅λ‹ˆλ‹€!")
                await message.channel.send(embed = tmpembed)
                return
            else:
                choiceOfCpu = random.choice(hands)
                if choiceOfCpu == str(reaction.emoji):
                    tmpembed = discord.Embed(title = "λΉ„κ²ΌμŠ΅λ‹ˆλ‹€!", description = f"봇도 {choiceOfCpu}λ₯Ό λƒˆμŠ΅λ‹ˆλ‹€!")
                    await message.channel.send(embed = tmpembed)
                    return
                winlist = ["✊✌️", "βœŒοΈπŸ–οΈ", "πŸ–οΈβœŠ"]
                if str(reaction.emoji) + choiceOfCpu in winlist:
                    tmpembed = discord.Embed(title = "당신이 μ΄κ²ΌμŠ΅λ‹ˆλ‹€!", description = f"봇은 {choiceOfCpu}λ₯Ό λƒˆμŠ΅λ‹ˆλ‹€!")
                    await message.channel.send(embed = tmpembed)
                    return
                else:
                    tmpembed = discord.Embed(title = "봇이 μ΄κ²ΌμŠ΅λ‹ˆλ‹€!", description = f"봇은 {choiceOfCpu}λ₯Ό λƒˆμŠ΅λ‹ˆλ‹€!")
                    await message.channel.send(embed = tmpembed)
                    return
        
        elif gamenumber == "2" or gamenumber == "μ—…λ‹€μš΄":
            tmpembed = discord.Embed(title = "↕️ μ—…λ‹€μš΄", description = "1~100κΉŒμ§€ μˆ«μžμ€‘ ν•˜λ‚˜λ₯Ό κ³¨λžμ„ λ•Œ 그것을 λ§žμΆ”λŠ” κ²Œμž„μž…λ‹ˆλ‹€. κΈ°νšŒλŠ” 총 5번 μžˆμŠ΅λ‹ˆλ‹€. 숫자λ₯Ό μΆ”μΈ‘ν•˜λ©΄ 봇이 μƒκ°ν•œ μˆ«μžλ³΄λ‹€ 큰지 μž‘μ€μ§€ μ•Œλ €μ€λ‹ˆλ‹€.")
            await message.channel.send(embed = tmpembed)

            choiceOfCpu = random.randint(1, 100)
            before = ""

            for x in range(5):
                tmpembed = discord.Embed(title = f"{before}{5 - x}번의 κΈ°νšŒκ°€ λ‚¨μ•˜μŠ΅λ‹ˆλ‹€.", description = "1~100κΉŒμ§€ μˆ«μžμ€‘ ν•˜λ‚˜λ₯Ό κ³ λ₯΄μ„Έμš”.")
                await message.channel.send(embed = tmpembed)
                def check(msg):
                    return msg.author == message.author
                try:
                    msg = await app.wait_for('message', timeout = 10, check = check)
                except asyncio.TimeoutError:
                    tmpembed = discord.Embed(title = "봇이 μŠΉλ¦¬ν•˜μ˜€μŠ΅λ‹ˆλ‹€!", description = "μ„ νƒν•˜λŠ” 데 μ‹œκ°„μ΄ λ„ˆλ¬΄ 였래 κ±Έλ ΈμŠ΅λ‹ˆλ‹€!")
                    await message.channel.send(embed = tmpembed)
                    return
                else:
                    try: a = int(msg.content)
                    except: before = "숫자λ₯Ό μž…λ ₯ν•΄ μ£Όμ„Έμš”. "
                    else:
                        if choiceOfCpu == a:
                            tmpembed = discord.Embed(title = "당신이 μ΄κ²ΌμŠ΅λ‹ˆλ‹€!", description = f"봇이 μƒκ°ν•œ μˆ«μžλŠ” {choiceOfCpu}μ˜€μŠ΅λ‹ˆλ‹€.")
                            await message.channel.send(embed = tmpembed)
                            return
                        elif choiceOfCpu > a:
                            before = f"{a}보닀 ν½λ‹ˆλ‹€! "
                        else:
                            before = f"{a}보닀 μž‘μŠ΅λ‹ˆλ‹€! "
            
            tmpembed = discord.Embed(title = "봇이 μ΄κ²ΌμŠ΅λ‹ˆλ‹€!", description = f"봇이 μƒκ°ν•œ μˆ«μžλŠ” {choiceOfCpu}μ˜€μŠ΅λ‹ˆλ‹€.")
            await message.channel.send(embed = tmpembed)

        elif gamenumber == "3" or gamenumber == "μŠ¬λΌμ΄λ”© 퍼즐":
            tmpembed = discord.Embed(title = "πŸ”  16 μŠ¬λΌμ΄λ”© 퍼즐", description = "각각의 타일을 λ°€μ–΄μ„œ AλΆ€ν„° OκΉŒμ§€ 숫자λ₯Ό μˆœμ„œλŒ€λ‘œ μ •λ ¬ν•˜λŠ” νΌμ¦μž…λ‹ˆλ‹€.")
            await message.channel.send(embed = tmpembed)

            mixingCount = 0

            tmpembed = discord.Embed(title = "λ‚œμ΄λ„λ₯Ό μ„ νƒν•˜μ„Έμš”!", description = "🟩 : 쉬움\n🟧 : 보톡\nπŸŸ₯ : 어렀움")
            difficulty = await message.channel.send(embed = tmpembed)
            await difficulty.add_reaction("🟩")
            await difficulty.add_reaction("🟧")
            await difficulty.add_reaction("πŸŸ₯")

            difficulties = ["🟩", "🟧", "πŸŸ₯"]
            def check(reaction, user):
                return user == message.author and str(reaction.emoji) in difficulties
            try:
                reaction, user = await app.wait_for('reaction_add', timeout = 40, check = check)
            except asyncio.TimeoutError:
                tmpembed = discord.Embed(title = "μ‹œκ°„ 초과!", description = "λ‚œμ΄λ„λ₯Ό μ„ νƒν•˜λŠ” 데 μ‹œκ°„μ΄ λ„ˆλ¬΄ 였래 κ±Έλ ΈμŠ΅λ‹ˆλ‹€!")
                await message.channel.send(embed = tmpembed)
                return
            else:
                if str(reaction.emoji) == difficulties[0]:
                    mixingCount = random.randint(5, 10)
                if str(reaction.emoji) == difficulties[1]:
                    mixingCount = random.randint(15, 25)
                if str(reaction.emoji) == difficulties[2]:
                    mixingCount = random.randint(30, 50)

            xpt, ypt = 3, 3
            doneBoard = [ [1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16] ]
            board =     [ [1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16] ]
            
            def moveTo(mx, my, xpt, ypt):
                if not(0 <= (xpt + mx) < 4): return False
                if not(0 <= (ypt + my) < 4): return False
                tmp = board[ypt + my][xpt + mx]
                board[ypt + my][xpt + mx] = board[ypt][xpt]
                board[ypt][xpt] = tmp
                return True

            def boardStr():
                strs = ""
                for y in range(4):
                    for x in range(4):
                        if board[y][x] == 16:
                            strs += "πŸŸͺ"
                        else:
                            strs += ":regional_indicator_" + ("abcdefghijklmno")[board[y][x] - 1] + ":"
                    strs += "\n"
                return strs

            tmpembed = discord.Embed(title = "타일을 μ„žλŠ” μ€‘μž…λ‹ˆλ‹€.")
            main = await message.channel.send(embed = tmpembed)
            await main.add_reaction("⬆")
            await main.add_reaction("⬇")
            await main.add_reaction("β¬…")
            await main.add_reaction("➑")
            await main.add_reaction("🚫")

            cntMix, cntSolv = 0, 0
            moving = ""

            while cntMix < mixingCount:
                canmove = [[1, 0], [-1, 0], [0, 1], [0, -1]]
                movedirc = ["β¬…", "➑", "⬆", "⬇"]
                wantmove = random.randint(0, 3)
                if moveTo(canmove[wantmove][0], canmove[wantmove][1], xpt, ypt) == True:
                    if len(moving) >= 1:
                        if moving[len(moving) - 1] == movedirc[0] and wantmove == 1:
                            moving = moving[0: len(moving) - 1]
                            xpt += canmove[wantmove][0]
                            ypt += canmove[wantmove][1]
                            cntMix -= 1
                            continue
                        if moving[len(moving) - 1] == movedirc[1] and wantmove == 0:
                            moving = moving[0: len(moving) - 1]
                            xpt += canmove[wantmove][0]
                            ypt += canmove[wantmove][1]
                            cntMix -= 1
                            continue
                        if moving[len(moving) - 1] == movedirc[2] and wantmove == 3:
                            moving = moving[0: len(moving) - 1]
                            xpt += canmove[wantmove][0]
                            ypt += canmove[wantmove][1]
                            cntMix -= 1
                            continue
                        if moving[len(moving) - 1] == movedirc[3] and wantmove == 2:
                            moving = moving[0: len(moving) - 1]
                            xpt += canmove[wantmove][0]
                            ypt += canmove[wantmove][1]
                            cntMix -= 1
                            continue
                    xpt += canmove[wantmove][0]
                    ypt += canmove[wantmove][1]
                    moving += movedirc[wantmove]
                    cntMix += 1

            while 1:
                tmpembed = discord.Embed(title = "타일을 λ°€ λ°©ν–₯을 μ„ νƒν•˜μ„Έμš”. [포기: 🚫]", description = boardStr())
                await main.edit(embed = tmpembed)

                arrows = ["⬆", "⬇", "β¬…", "➑", "🚫"]
                def check(reaction, user):
                    return user == message.author and str(reaction.emoji) in arrows
                try:
                    reaction, user = await app.wait_for('reaction_add', timeout = 40, check = check)
                except asyncio.TimeoutError:
                    tmpembed = discord.Embed(title = "μ‹€νŒ¨ν•˜μ˜€μŠ΅λ‹ˆλ‹€!", description = "μƒκ°ν•˜λŠ” 데 μ‹œκ°„μ΄ λ„ˆλ¬΄ 였래 κ±Έλ ΈμŠ΅λ‹ˆλ‹€!")
                    await message.channel.send(embed = tmpembed)
                    return
                else:
                    if str(reaction.emoji) == arrows[4]:
                        tmpembed = discord.Embed(title = "봇이 μ΄κ²ΌμŠ΅λ‹ˆλ‹€!", description = f"봇이 타일을 μ„žμ€ 과정은 {moving}μ΄μ—ˆμŠ΅λ‹ˆλ‹€.")
                        await message.channel.send(embed = tmpembed)
                        return
                    if str(reaction.emoji) == arrows[0]:
                        if moveTo(0, 1, xpt, ypt) == True:
                            ypt += 1
                            cntSolv += 1
                    if str(reaction.emoji) == arrows[1]:
                        if moveTo(0, -1, xpt, ypt) == True:
                            ypt += -1
                            cntSolv += 1
                    if str(reaction.emoji) == arrows[2]:
                        if moveTo(1, 0, xpt, ypt) == True:
                            xpt += 1
                            cntSolv += 1
                    if str(reaction.emoji) == arrows[3]:
                        if moveTo(-1, 0, xpt, ypt) == True:
                            xpt += -1
                            cntSolv += 1
                    try:
                        await reaction.remove(message.author)
                    except:
                        time.sleep(0)

                    if board == doneBoard: break
            
            tmpembed = discord.Embed(title = "타일을 λ°€ λ°©ν–₯을 μ„ νƒν•˜μ„Έμš”. [포기: 🚫]", description = boardStr())
            await main.edit(embed = tmpembed)
            tmpembed = discord.Embed(title = "당신이 μ΄κ²ΌμŠ΅λ‹ˆλ‹€!", description = f"μ„žμœΌλ©΄μ„œ 타일을 움직인 νšŸμˆ˜λŠ” {cntMix}이고 ν’€λ©΄μ„œ 타일을 움직인 νšŸμˆ˜λŠ” {cntSolv}μž…λ‹ˆλ‹€. 봇이 타일을 μ„žμ€ 과정은 {moving}μ΄μ—ˆμŠ΅λ‹ˆλ‹€.")
            await message.channel.send(embed = tmpembed)

        elif gamenumber == "4" or gamenumber == "틱택토":
            tmpembed = discord.Embed(title = "⏺️ 틱택토", description = "λ²ˆκ°ˆμ•„ κ°€λ©° 칸에 ν‘œμ‹œλ₯Ό ν•˜κ³  ν•œ 쀄을 λ¨Όμ € μ™„μ„±ν•˜λ©΄ μŠΉλ¦¬ν•©λ‹ˆλ‹€.")
            await message.channel.send(embed = tmpembed)

            board = Board.fromstring('.')

            def getboard(board, selX, selY):
                if selY == 1:
                    strs = ":blue_square::arrow_down::two::three:\n"
                if selY == 2:
                    strs = ":blue_square::one::arrow_down::three:\n"
                if selY == 3:
                    strs = ":blue_square::one::two::arrow_down:\n"
                a = 0
                for x in range(3):
                    if x == 0:
                        if selX - 1 == x: strs += ":arrow_right:"
                        else: strs += ":regional_indicator_a:"
                    if x == 1:
                        if selX - 1 == x: strs += ":arrow_right:"
                        else: strs += ":regional_indicator_b:"
                    if x == 2:
                        if selX - 1 == x: strs += ":arrow_right:"
                        else: strs += ":regional_indicator_c:"
                    for y in range(3):
                        if board[a] ==  '.':
                            strs += "πŸŸͺ"
                        if board[a] ==  'o':
                            strs += ":regional_indicator_o:"
                        if board[a] ==  'x':
                            strs += ":regional_indicator_x:"
                        a += 1
                    strs += "\n"
                return strs

            tmpembed = discord.Embed(title = "λ‘œλ”© μ€‘μž…λ‹ˆλ‹€.")
            main = await message.channel.send(embed = tmpembed)
            await main.add_reaction("πŸ‡¦")
            await main.add_reaction("πŸ‡§")
            await main.add_reaction("πŸ‡¨")
            await main.add_reaction("1️⃣")
            await main.add_reaction("2️⃣")
            await main.add_reaction("3️⃣")
            await main.add_reaction("β˜‘οΈ")

            selectedX, selectedY = 1, 1
            
            while 1:
                tmpembed = discord.Embed(title = "μ•ŒνŒŒλ²³κ³Ό 숫자λ₯Ό μ„ νƒν•˜κ³  β˜‘οΈλ₯Ό λˆŒλŸ¬μ£Όμ„Έμš”.", description = getboard(str(board), selectedX, selectedY))
                await main.edit(embed = tmpembed)

                choices = ["πŸ‡¦", "πŸ‡§", "πŸ‡¨", "1️⃣", "2️⃣", "3️⃣", "β˜‘οΈ"]
                def check(reaction, user):
                    return user == message.author and str(reaction.emoji) in choices
                try:
                    reaction, user = await app.wait_for('reaction_add', timeout = 30, check = check)
                except asyncio.TimeoutError:
                    tmpembed = discord.Embed(title = "당신은 νŒ¨λ°°ν•˜μ˜€μŠ΅λ‹ˆλ‹€!", description = "칸을 κ³ λ₯΄λŠ” 데 μ‹œκ°„μ΄ λ„ˆλ¬΄ 였래 κ±Έλ ΈμŠ΅λ‹ˆλ‹€!")
                    await message.channel.send(embed = tmpembed)
                    return
                else:
                    if str(reaction.emoji) == "β˜‘οΈ":
                        if board[selectedX, selectedY] == " ":
                            board[selectedX, selectedY] = "o"
                            ismewin = False
                            if board[1, 1] == board[1, 2] == board[1, 3] == "o":
                                ismewin = True
                            if board[2, 1] == board[2, 2] == board[2, 3] == "o":
                                ismewin = True
                            if board[3, 1] == board[3, 2] == board[3, 3] == "o":
                                ismewin = True
                            if board[1, 1] == board[2, 1] == board[3, 1] == "o":
                                ismewin = True
                            if board[1, 2] == board[2, 2] == board[3, 2] == "o":
                                ismewin = True
                            if board[1, 3] == board[2, 3] == board[3, 3] == "o":
                                ismewin = True
                            if board[1, 1] == board[2, 2] == board[3, 3] == "o":
                                ismewin = True
                            if board[1, 3] == board[2, 2] == board[1, 3] == "o":
                                ismewin = True
                            if ismewin:
                                tmpembed = discord.Embed(title = "μ•ŒνŒŒλ²³κ³Ό 숫자λ₯Ό μ„ νƒν•˜κ³  β˜‘οΈλ₯Ό λˆŒλŸ¬μ£Όμ„Έμš”.", description = getboard(str(board), selectedX, selectedY))
                                await main.edit(embed = tmpembed)
                                tmpembed = discord.Embed(title = "당신이 μ΄κ²ΌμŠ΅λ‹ˆλ‹€!")
                                await message.channel.send(embed = tmpembed)
                                return
                            try:
                                airesult = ai.evaluate(board, "x")
                                aido = random.choice(airesult.positions)
                                board[aido] = "x"
                                ismewin = False
                                if board[1, 1] == board[1, 2] == board[1, 3] == "x":
                                    ismewin = True
                                if board[2, 1] == board[2, 2] == board[2, 3] == "x":
                                    ismewin = True
                                if board[3, 1] == board[3, 2] == board[3, 3] == "x":
                                    ismewin = True
                                if board[1, 1] == board[2, 1] == board[3, 1] == "x":
                                    ismewin = True
                                if board[1, 2] == board[2, 2] == board[3, 2] == "x":
                                    ismewin = True
                                if board[1, 3] == board[2, 3] == board[3, 3] == "x":
                                    ismewin = True
                                if board[1, 1] == board[2, 2] == board[3, 3] == "x":
                                    ismewin = True
                                if board[1, 3] == board[2, 2] == board[1, 3] == "x":
                                    ismewin = True
                                if ismewin:
                                    tmpembed = discord.Embed(title = "μ•ŒνŒŒλ²³κ³Ό 숫자λ₯Ό μ„ νƒν•˜κ³  β˜‘οΈλ₯Ό λˆŒλŸ¬μ£Όμ„Έμš”.", description = getboard(str(board), selectedX, selectedY))
                                    await main.edit(embed = tmpembed)
                                    tmpembed = discord.Embed(title = "봇이 μ΄κ²ΌμŠ΅λ‹ˆλ‹€!")
                                    await message.channel.send(embed = tmpembed)
                                    return
                            except:
                                tmpembed = discord.Embed(title = "μ•ŒνŒŒλ²³κ³Ό 숫자λ₯Ό μ„ νƒν•˜κ³  β˜‘οΈλ₯Ό λˆŒλŸ¬μ£Όμ„Έμš”.", description = getboard(str(board), selectedX, selectedY))
                                await main.edit(embed = tmpembed)
                                tmpembed = discord.Embed(title = "λΉ„κ²ΌμŠ΅λ‹ˆλ‹€!")
                                await message.channel.send(embed = tmpembed)
                                return
                    elif str(reaction.emoji) == "πŸ‡¦":
                        selectedX = 1
                    elif str(reaction.emoji) == "πŸ‡§":
                        selectedX = 2
                    elif str(reaction.emoji) == "πŸ‡¨":
                        selectedX = 3
                    elif str(reaction.emoji) == "1️⃣":
                        selectedY = 1
                    elif str(reaction.emoji) == "2️⃣":
                        selectedY = 2
                    elif str(reaction.emoji) == "3️⃣":
                        selectedY = 3
                    try:
                        await reaction.remove(message.author)
                    except:
                        time.sleep(0)

        else:
            tmpembed = discord.Embed(title = "Unknown Minigame Number", description = "Send `z.help`to show minigames list")
            await message.channel.send(embed = tmpembed)
        
    if message.content.startswith("z.eval") and isModer(message.author):
        await message.channel.send(eval(message.content[7:]))

    elif message.content.startswith("z.exec") and isModer(message.author):
        exec(message.content[7:])
Example #10
0
 def test_when_not_token_turn(self):
     with self.assertRaisesRegex(ValueError,
                                 "not x's turn to play: xxo......"):
         ai.evaluate(Board.fromstring('xxo'), 'x')
Example #11
0
    def test_when_board_is_invalid(self):
        with self.assertRaisesRegex(ValueError, 'invalid board: xxx......'):
            ai.evaluate(Board.fromstring('xxx'), 'x')

        with self.assertRaisesRegex(ValueError, 'invalid board: xxx......'):
            ai.evaluate(Board.fromstring('xxx'), 'o')
Example #12
0
 def test_when_not_a_token(self):
     with self.assertRaisesRegex(ValueError, 'must be a token: .'):
         ai.evaluate(Board.fromstring(), '.')
Example #13
0
 def test_xeooeexex(self):
     self.assertEqual(
         ai.evaluate(Board.fromstring('x.oo..x.x'), 'o').positions,
         [(1, 2), (2, 2), (2, 3), (3, 2)])
Example #14
0
 def test_xeeeeeeee(self):
     self.assertEqual(
         ai.evaluate(Board.fromstring('x'), 'o').positions, [(2, 2)])
Example #15
0
 def test_xoexoeeee(self):
     self.assertEqual(
         ai.evaluate(Board.fromstring('xo.xo.'), 'o').positions, [(3, 2)])
Example #16
0
 def setUp(self):
     self.board = Board.fromstring('x...o')
Example #17
0
 def test_when_layout_contains_non_pieces(self):
     self.assertEqual(str(Board.fromstring('x.o-*x1o^')), 'x.o..x.o.')
Example #18
0
 def test_eeeexeeee(self):
     self.assertEqual(
         ai.evaluate(Board.fromstring('....x'), 'o').positions, [(1, 1),
                                                                 (1, 3),
                                                                 (3, 1),
                                                                 (3, 3)])