Exemple #1
0
 def test_kakuro_not_solution(self):
     game = GameField(3, 3)
     cell_column = Cell(CellType.RULES, column_rule=3, length_column=2)
     cell_row = Cell(CellType.RULES, row_rule=17, length_row=2)
     game.init_cell(0, 1, cell_column)
     game.init_cell(1, 0, cell_row)
     solver = Solver(game)
     with self.assertRaises(exc.KakuroNotSolution):
         self.assertRaises(solver.solve())
Exemple #2
0
 def __init__(self, width, height):
     self.width = width
     self.height = height
     self.field = []
     self.row_pairs = []
     self.column_pairs = []
     self.all_pairs = []
     for x in range(0, height):
         self.field.append([])
         for y in range(0, width):
             self.field[x].append(Cell(CellType.NO_ACTIVE))
Exemple #3
0
 def test_get_cell(self):
     date = '0|1|0|0|16|2'
     parser = Parser()
     actual = parser.get_cell(date, 'fake_file')
     cell = Cell(CellType.RULES,
                 row_rule=0,
                 length_row=0,
                 column_rule=16,
                 length_column=2)
     expected = [16, 2]
     for key in actual:
         self.assertEqual(tuple([0, 1]), key)
         self.assertTrue(actual[key].get_length_column() in expected)
         self.assertTrue(actual[key].get_rules()[1] in expected)
Exemple #4
0
 def setUp(self):
     self.game = GameField(4, 4)
     self.game.init_cell(
         0, 1, Cell(CellType.RULES, column_rule=16, length_column=2))
     self.game.init_cell(
         0, 2, Cell(CellType.RULES, column_rule=15, length_column=3))
     self.game.init_cell(1, 0,
                         Cell(CellType.RULES, row_rule=17, length_row=2))
     self.game.init_cell(2, 0,
                         Cell(CellType.RULES, row_rule=15, length_row=3))
     self.game.init_cell(3, 1, Cell(CellType.RULES,
                                    row_rule=3,
                                    length_row=2))
     self.game.init_cell(
         1, 3, Cell(CellType.RULES, column_rule=4, length_column=2))
Exemple #5
0
 def put_cell(self, sum_row, length_row, sum_column, length_column, x, y,
              root):
     try:
         row_rule = int(sum_row.get())
         column_rule = int(sum_column.get())
         row = int(length_row.get())
         column = int(length_column.get())
     except Exception as e:
         self.throw_exception('Argument error',
                              'One or more argument are NaN', root)
         return
     if not self.check_arguments(row_rule, column_rule, row, column, x, y,
                                 root):
         return
     self.close_window(root)
     cell = Cell(CellType.RULES,
                 row_rule=row_rule,
                 column_rule=column_rule,
                 length_row=row,
                 length_column=column)
     self.game_field.init_cell(x, y, cell)
     self.redraw()
Exemple #6
0
 def add_cell(self, line):
     frame = line.split('|')
     if len(frame) != 6:
         print('Incorrect line')
         return
     try:
         pos_x = self.get_frame(frame[0])
         pos_y = self.get_frame(frame[1])
         row_sum = self.get_frame(frame[2])
         row_length = self.get_frame(frame[3])
         column_sum = self.get_frame(frame[4])
         column_length = self.get_frame(frame[5])
     except Exception as e:
         print('incorrect line')
         return
     cell = Cell(CellType.RULES,
                 row_rule=row_sum,
                 column_rule=column_sum,
                 length_row=row_length,
                 length_column=column_length)
     self.game.init_cell(pos_x, pos_y, cell)
     self.all_line.append(line)
Exemple #7
0
 def test_get_rule(self):
     rule_row = 10
     rule_column = 10
     c = Cell(CellType.RULES, column_rule=rule_column, row_rule=rule_row)
     self.assertEqual([rule_row, rule_column], c.get_rules())
Exemple #8
0
 def test_get_type(self):
     type = CellType.NO_ACTIVE
     c = Cell(type)
     self.assertEqual(type, c.get_type())
Exemple #9
0
 def test_get_value(self):
     value = 10
     c = Cell(CellType.PLAY, value)
     self.assertEqual(value, c.get_value())
Exemple #10
0
 def test_init_put_rule_cell_column(self):
     game = GameField(10, 10)
     cell = Cell(CellType.RULES, column_rule=10, length_column=2)
     game.init_cell(5, 5, cell)
     self.assertEqual(CellType.PLAY, game.field[6][5].get_type())
     self.assertEqual(CellType.PLAY, game.field[7][5].get_type())
Exemple #11
0
 def test_init_put_rule_cell_row(self):
     game = GameField(10, 10)
     cell = Cell(CellType.RULES, row_rule=10, length_row=2)
     game.init_cell(5, 5, cell)
     self.assertEqual(CellType.PLAY, game.field[5][6].get_type())
     self.assertEqual(CellType.PLAY, game.field[5][7].get_type())
Exemple #12
0
 def test_init_put_play_cell(self):
     game = GameField(10, 10)
     cell = Cell(CellType.PLAY, value=10)
     game.init_cell(5, 5, cell)
     self.assertEqual(cell, game.field[5][5])
Exemple #13
0
 def test_is_rule(self):
     c = Cell(CellType.RULES)
     self.assertTrue(c.is_rules())
Exemple #14
0
 def init_column(self, pos_x, pos_y, length_column, pair):
     for x in range(0, length_column):
         cell = Cell(CellType.PLAY)
         self.field[pos_x + x][pos_y] = cell
         pair.column_slaves.append(tuple([pos_x + x, pos_y]))
Exemple #15
0
 def init_row(self, pos_x, pos_y, length_row, pair):
     for y in range(0, length_row):
         cell = Cell(CellType.PLAY, 0)
         self.field[pos_x][pos_y + y] = cell
         pair.row_slaves.append(tuple([pos_x, pos_y + y]))
def print_field(field):
    for x in range(0, len(field)):
        line = ""
        for y in range(0, len(field)):
            if field[x][y].get_type() == CellType.NO_ACTIVE:
                line += ' # \t'
            if field[x][y].get_type() == CellType.PLAY:
                line += ' ' + str(field[x][y].get_value()) + ' \t'
            if field[x][y].get_type() == CellType.RULES:
                line += ' ' + str(field[x][y].get_rules()[1]) + '\\' + str(
                    field[x][y].get_rules()[0]) + '\t'
        print(line)


if __name__ == '__main__':
    game = GameField(4, 4)
    #print_field(game.field)
    #print('===================================')
    game.init_cell(0, 1, Cell(CellType.RULES, column_rule=16, length_column=2))
    game.init_cell(0, 2, Cell(CellType.RULES, column_rule=15, length_column=3))
    game.init_cell(1, 0, Cell(CellType.RULES, row_rule=17, length_row=2))
    game.init_cell(2, 0, Cell(CellType.RULES, row_rule=15, length_row=3))
    game.init_cell(3, 1, Cell(CellType.RULES, row_rule=3, length_row=2))
    game.init_cell(1, 3, Cell(CellType.RULES, column_rule=4, length_column=2))
    print_field(game.field)
    #solver = Solver(game)
    #new_field = solver.solve()
    #print_field(new_field)
    print(tuple([1, 2, 3]))