Решение на Шахматни фенове от Мария Симеонова

Обратно към всички решения

Към профила на Мария Симеонова

Резултати

  • 6 точки от тестове
  • 0 бонус точки
  • 6 точки общо
  • 11 успешни тест(а)
  • 6 неуспешни тест(а)

Код

class ChessException(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return self.value
class ChessScore:
def __init__(self, figures):
self._figures = figures
self.values = {'R': 5, 'N': 3, 'B': 3, 'K': 4, 'Q': 9, 'P': 1, 'r': 5, 'n': 3, 'b': 3, 'k': 4, 'q': 9, 'p': 1}
def __int__(self):
figures_sum = 0
for figure in self._figures:
figures_sum += self.values[figure]
return figures_sum
def __str__(self):
return str(int(self))
def __lt__(self, other):
return int(self) < int(other)
def __le__(self, other):
return int(self) <= int(other)
def __gt__(self, other):
return int(self) > int(other)
def __ge__(self, other):
return int(self) >= int(other)
def __eq__(self, other):
return int(self) == int(other)
def __ne__(self, other):
return int(self) != int(other)
def __add__(self, other):
return int(self) + int(other)
def __sub__(self, other):
return int(self) - int(other)
class ChessPosition:
def __init__(self, fen):
self._fen = fen
self._split_fen = fen.split("/")
for row in self._split_fen:
if 'kk' in row.lower():
raise ChessException("kings")
if self._fen.count('K') != 1 and self._fen.count('k') != 1:
raise ChessException("kings")
if 'p' in self._split_fen[0].lower() and 'p' in self._split_fen[7].lower():
raise ChessException("pawns")
def __getitem__(self, item):
return None
def __str__(self):
return self._fen
def __len__(self):
figures = []
for figure in self._fen:
if figure in ['R', 'N', 'B', 'K', 'Q', 'P','r', 'n', 'b', 'k', 'q', 'p']:
figures.append(figure)
figure_score = ChessScore(figures)
return int(figure_score)
def get_white_score(self):
white = []
for figure in self._fen:
if figure in ['R', 'N', 'B', 'K', 'Q', 'P']:
white.append(figure)
return ChessScore(white)
def get_black_score(self):
black = []
for figure in self._fen:
if figure in ['r', 'n', 'b', 'k', 'q', 'p']:
black.append(figure)
return ChessScore(black)
def white_is_winning(self):
return self.get_white_score() > self.get_black_score()
def black_is_winning(self):
return self.get_white_score() < self.get_black_score()
def is_equal(self):
return self.get_white_score() == self.get_black_score()

Лог от изпълнението

.E...F.EFE.E.....
======================================================================
ERROR: test_against_touching_kings (test.TestChessPosition)
Test for kings next to each other.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221115154139/lib/language/python/runner.py", line 67, in thread
    raise result
Exception: No exception raised on: k7/K7/8/8/8/8/8/8

======================================================================
ERROR: test_king_count (test.TestChessPosition)
Test for missing or multiple kings.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221115154139/lib/language/python/runner.py", line 67, in thread
    raise result
Exception: No exception raised on: k7/8/2K5/8/8/4k3/8/8

======================================================================
ERROR: test_pawns_position (test.TestChessPosition)
Test for incorrect pawns.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221115154139/lib/language/python/runner.py", line 67, in thread
    raise result
Exception: No exception raised on: p7/8/k7/8/7K/8/8/8

======================================================================
ERROR: test_validation_conflict (test.TestChessPosition)
Test for correct Exception on multiple validation fails.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221115154139/lib/language/python/runner.py", line 67, in thread
    raise result
Exception: No exception raised on: P7/K7/k7/8/8/8/8/8

======================================================================
FAIL: test_getitem (test.TestChessPosition)
Test getitem functionality.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221115154139/lib/language/python/runner.py", line 67, in thread
    raise result
AssertionError: None != 'K'

======================================================================
FAIL: test_len (test.TestChessPosition)
Test number of pieces for a position.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/storage/deedee/data/rails/pyfmi-2022/releases/20221115154139/lib/language/python/runner.py", line 67, in thread
    raise result
AssertionError: 21 != 7

----------------------------------------------------------------------
Ran 17 tests in 0.166s

FAILED (failures=2, errors=4)

История (2 версии и 1 коментар)

Мария обнови решението на 29.11.2022 16:45 (преди почти 2 години)

+class ChessException(Exception):
+ def __init__(self, value):
+ self.value = value
+
+ def __str__(self):
+ return self.value
+
+
+class ChessScore:
+ def __init__(self, figures):
+ self._figures = figures
+ self.values = {'R': 5, 'N': 3, 'B': 3, 'K': 4, 'Q': 9, 'P': 1, 'r': 5, 'n': 3, 'b': 3, 'k': 4, 'q': 9, 'p': 1}
+
+ def __int__(self):
+ figures_sum = 0
+ for figure in self._figures:
+ figures_sum += self.values[figure]
+ return figures_sum
+
+ def __str__(self):
+ return str(int(self))
+
+ def __lt__(self, other):
+ return int(self) < int(other)
+
+ def __le__(self, other):
+ return int(self) <= int(other)
+
+ def __gt__(self, other):
+ return int(self) > int(other)
+
+ def __ge__(self, other):
+ return int(self) >= int(other)
+
+ def __eq__(self, other):
+ return int(self) == int(other)
+
+ def __ne__(self, other):
+ return int(self) != int(other)
+
+ def __add__(self, other):
+ return int(self) + int(other)
+
+ def __sub__(self, other):
+ return int(self) - int(other)
+
+
+class ChessPosition:
+ def __init__(self, fen):
+ self._fen = fen
+ self._split_fen = fen.split("/")
+ for row in self._split_fen:
+ if 'kk' in row.lower():
+ raise ChessException("kings")
+ if self._fen.count('K') != 1 and self._fen.count('k') != 1:
+ raise ChessException("kings")
+ if 'p' in self._split_fen[0].lower() and 'p' in self._split_fen[7].lower():
+ raise ChessException("pawns")
+
+ def __str__(self):
+ return self._fen
+
+ def __len__(self):
+ figures = []
+ for figure in self._fen:
+ if figure in ['R', 'N', 'B', 'K', 'Q', 'P','r', 'n', 'b', 'k', 'q', 'p']:
+ figures.append(figure)
+ figure_score = ChessScore(figures)
+ return int(figure_score)
+
+ def get_white_score(self):
+ white = []
+ for figure in self._fen:
+ if figure in ['R', 'N', 'B', 'K', 'Q', 'P']:
+ white.append(figure)
+ return ChessScore(white)
+
+ def get_black_score(self):
+ black = []
+ for figure in self._fen:
+ if figure in ['r', 'n', 'b', 'k', 'q', 'p']:
+ black.append(figure)
+ return ChessScore(black)
+
+ def white_is_winning(self):
+ return self.get_white_score() > self.get_black_score()
+
+ def black_is_winning(self):
+ return self.get_white_score() < self.get_black_score()
+
+ def is_equal(self):
+ return self.get_white_score() == self.get_black_score()

Мария обнови решението на 29.11.2022 17:05 (преди почти 2 години)

class ChessException(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return self.value
class ChessScore:
def __init__(self, figures):
self._figures = figures
self.values = {'R': 5, 'N': 3, 'B': 3, 'K': 4, 'Q': 9, 'P': 1, 'r': 5, 'n': 3, 'b': 3, 'k': 4, 'q': 9, 'p': 1}
def __int__(self):
figures_sum = 0
for figure in self._figures:
figures_sum += self.values[figure]
return figures_sum
def __str__(self):
return str(int(self))
def __lt__(self, other):
return int(self) < int(other)
def __le__(self, other):
return int(self) <= int(other)
def __gt__(self, other):
return int(self) > int(other)
def __ge__(self, other):
return int(self) >= int(other)
def __eq__(self, other):
return int(self) == int(other)
def __ne__(self, other):
return int(self) != int(other)
def __add__(self, other):
return int(self) + int(other)
def __sub__(self, other):
return int(self) - int(other)
class ChessPosition:
def __init__(self, fen):
self._fen = fen
self._split_fen = fen.split("/")
for row in self._split_fen:
if 'kk' in row.lower():
raise ChessException("kings")
if self._fen.count('K') != 1 and self._fen.count('k') != 1:
raise ChessException("kings")
if 'p' in self._split_fen[0].lower() and 'p' in self._split_fen[7].lower():
raise ChessException("pawns")
+ def __getitem__(self, item):
+ return None
+
def __str__(self):
return self._fen
def __len__(self):
figures = []
for figure in self._fen:
if figure in ['R', 'N', 'B', 'K', 'Q', 'P','r', 'n', 'b', 'k', 'q', 'p']:
figures.append(figure)
figure_score = ChessScore(figures)
return int(figure_score)
def get_white_score(self):
white = []
for figure in self._fen:
if figure in ['R', 'N', 'B', 'K', 'Q', 'P']:
white.append(figure)
return ChessScore(white)
def get_black_score(self):
black = []
for figure in self._fen:
if figure in ['r', 'n', 'b', 'k', 'q', 'p']:
black.append(figure)
return ChessScore(black)
def white_is_winning(self):
return self.get_white_score() > self.get_black_score()
def black_is_winning(self):
return self.get_white_score() < self.get_black_score()
def is_equal(self):
- return self.get_white_score() == self.get_black_score()
+ return self.get_white_score() == self.get_black_score()