Exemplo n.º 1
0
def test(dim, d, num):
    lose_count = 0
    total_density = 0
    for i in range(num):
        b = gb.Board(dim, d)
        #print(b.mine_list)
        m = DSSP(b)
        #m = TSMP(b,True,True)
        print(m)
        density = 1 - (int(str(b.boom)) / b.mine_num)
        print('density = ' + str(density))
        if int(str(b.boom)) >= 1:
            print('lose')
            lose_count += 1
        print('the number of mines are queried: ' + str(b.boom))
        total_density += density
        score = total_density / num
    return (1 - lose_count / num), score
Exemplo n.º 2
0
import visualize
import time

cc = unit.Cc(1, (0, 1))
z1 = unit.Zu(2, (4, 0))
z2 = unit.Zu(3, (4, 3))
z3 = unit.Zu(4, (3, 1))
z4 = unit.Zu(5, (3, 2))
mc = unit.Shu(6, (0, 0))
zy = unit.Shu(7, (0, 3))
zf = unit.Shu(8, (2, 3))
hz = unit.Shu(9, (2, 0))
gy = unit.Heng(10, (2, 1))

all_units = [cc, z1, z2, z3, z4, mc, zy, zf, hz, gy]
new_board = game_board.Board(all_units)

visited = {}
queue = []
visited[new_board.to_string().tobytes()] = True
queue.append(new_board)
print("start: ")
print(new_board.to_int())
start = time.time()
final_board = game_board.BFS(queue, visited)
end = time.time()
print("finished in " + str(end - start))
if final_board is None:
    print("Unsolvable")
else:
    trace = []
Exemplo n.º 3
0
import game_board
import game_rules
import random
import game_ai_player
import time
import threading

b = game_board.Board()
b.initial()
rules = game_rules.Rules(game_board._n)
print(b)
depth = 2
'''
print(list(b.units(True)))
print(list(b.units(False)))

rules = game_rules.Rules(game_board._n)
for mx in rules.play(b, True):
    bx = rules.transformed_board(b, mx)
    print(bx)
'''
'''
class GameTreeBuilder(threading.Thread):
    def __init__(self, board, rules, turn, m0, depth):
        threading.Thread.__init__(self)
        self.depth = depth
        self.board = board
        self.rules = rules
        self.turn = turn
        self.tree = m0
        self.tooktime = 0
Exemplo n.º 4
0
import game_board as gb
from draw import draw_board
from alg import TSMP, constraint_satisfaction_gauss, constraint_satisfaction

b = gb.Board(10, 20)
print(b.mine_list)
m = TSMP(b, True, True)
print(m)
print('the number of mines are queried: ' + str(b.boom))

# test csp
# b = gb.Board(3, 0)
# b.mine_list = [[0, 2], [2, 2]]
# b.cell_matrix[0][2].is_mine = True
# b.cell_matrix[2][2].is_mine = True
# b.query([0, 0])
# gb.update_neighbors([0, 0], b)
# b.query([1, 0])
# gb.update_neighbors([1, 0], b)
# b.query([2, 0])
# gb.update_neighbors([2, 0], b)
# b.query([0, 1])
# gb.update_neighbors([0, 1], b)
# b.query([1, 1])
# gb.update_neighbors([1, 1], b)
# b.query([2, 1])
# gb.update_neighbors([2, 1], b)
# print(b.value_matrix)
# draw_board(b.value_matrix)
# fr = [[0, 1], [1, 1], [2, 1]]
# print(constraint_satisfaction_gauss(fr, b))
Exemplo n.º 5
0
import game_board

import board
import busio as io
import adafruit_is31fl3731

from time import sleep

if __name__ == "__main__":
    i2c = io.I2C(board.SCL, board.SDA)
    display = adafruit_is31fl3731.CharlieWing(i2c)

    game = game_board.Board(15, 7)
    counter = 0
    while True:
        game.show_board(display)
        game.next_gen()
        sleep(0.05)
        game.check_dead_state()
        counter += 1
        if counter == 100:
            game.randomize()