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

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

Към профила на Мария Марковска

Резултати

  • 8 точки от тестове
  • 0 бонус точки
  • 8 точки общо
  • 13 успешни тест(а)
  • 4 неуспешни тест(а)

Код

class ChessException(Exception):
def __init__(self, message):
self._message = message
super().__init__(self._message)
def Score(allfigures):
allpoints = 0
lst = range(1, 11)
nums = [format(x, '') for x in lst]
points = {"r" : 5, "n" : 3, "b" : 3, "k" : 4, "q" : 9, "p" : 1}
for i in allfigures:
if i not in nums and i!='/':
allpoints += points[i.lower()]
return allpoints
class ChessPosition():
def __init__(self, fen):
self.fen = fen
self._wscore=[]
self._bscore=[]
_row = 1
_column = 0
firstKing = 0
kngsRow = 0
kngsClmn = 0
raised = 0
lst = range(1, 11)
nums = [format(x, '') for x in lst]
if fen.count('k') != 1 or fen.count('K')!=1:
raise ChessException("kings")
for i in fen:
if i in nums:
_column += int(i)
else:
_column += 1
if i == '/' :
_row += 1
_column = 0
if i.upper() == 'K':
if kngsRow != 0:
if _row in (kngsRow, kngsRow + 1) and _column in range(kngsClmn - 1, kngsClmn + 2):
raise ChessException("kings")
else:
kngsRow = _row
kngsClmn = _column
if i.upper() == 'P':
if _row == 1 or _row == 8:
raise ChessException("pawns")
continue
def get_white_score(self):
for i in self.fen:
if i.isupper() == True:
self._wscore.append(i)
return Score(self._wscore)
def get_black_score(self):
for i in self.fen:
if i.islower() == True:
self._bscore.append(i)
return Score(self._bscore)
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()
def __repr__(self):
return self.fen
def __len__(self):
cntfig = 0
lst = range(1, 11)
nums = [format(x, '') for x in lst]
for i in self.fen:
if i not in nums and i!='/':
cntfig += 1
return cntfig
def __getitem__(self, pos):
column = 0
row = 1
lst = range(1, 11)
nums = [format(x, '') for x in lst]
letters = ["A", "B", "C", "D", "E", "F", "G", "H" ]
letter = letters.index(pos[0].upper()) + 1
for i in self.fen:
if i in nums:
column += int(i)
else:
column += 1
if i == '/' :
row += 1
column = 0
if column == letter and row == int(pos[1]):
return i
class ChessScore():
def __init__(self, figures):
self.__figures = figures
self.Allpoints = Score(self.__figures)
def __add__(self, otherChessScore):
return self.Allpoints + otherChessScore.Allpoints
def __sub__(self, otherChessScore):
return self.Allpoints - otherChessScore.Allpoints
def __eq__(self, otherChessScore):
return self.Allpoints == otherChessScore.Allpoints
def __ne__(self, otherChessScore):
return self.Allpoints != otherChessScore.Allpoints
def __le__(self, otherChessScore):
return self.Allpoints <= otherChessScore.Allpoints
def __lt__(self, otherChessScore):
return self.Allpoints < otherChessScore.Allpoints
def __gt__(self, otherChessScore):
return self.Allpoints > otherChessScore.Allpoints
def __int__(self):
return self.Allpoints

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

....FF.....FF....
======================================================================
FAIL: test_get_white_score (test.TestChessPosition)
Test get_white_score.
----------------------------------------------------------------------
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: 4 is not an instance of <class 'solution.ChessScore'>

======================================================================
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_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
AssertionError: 'pawns' != 'kings'
- pawns
+ kings


======================================================================
FAIL: test_white_is_winning (test.TestChessPosition)
Test white_is_winning.
----------------------------------------------------------------------
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: 4 is not an instance of <class 'solution.ChessScore'>

----------------------------------------------------------------------
Ran 17 tests in 0.168s

FAILED (failures=4)

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

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

+class ChessException(Exception):
+ def __init__(self, message):
+ self._message = message
+ super().__init__(self._message)
+
+def Score(allfigures):
+ allpoints = 0
+ lst = range(1, 11)
+ nums = [format(x, '') for x in lst]
+ points = {"r" : 5, "n" : 3, "b" : 3, "k" : 4, "q" : 9, "p" : 1}
+ for i in allfigures:
+ if i not in nums and i!='/':
+ allpoints += points[i.lower()]
+ return allpoints
+
+class ChessPosition():
+ def __init__(self, fen):
+ self.fen = fen
+ self._wscore=[]
+ self._bscore=[]
+ _row = 1
+ _column = 0
+ firstKing = 0
+ kngsRow = 0
+ kngsClmn = 0
+ raised = 0
+ lst = range(1, 11)
+ nums = [format(x, '') for x in lst]
+ if fen.count('k') != 1 or fen.count('K')!=1:
+ raise ChessException("kings")
+ for i in fen:
+ if i in nums:
+ _column += int(i)
+ else:
+ _column += 1
+ if i == '/' :
+ _row += 1
+ _column = 0
+ if i.upper() == 'K':
+ if kngsRow != 0:
+ if _row in (kngsRow, kngsRow + 1) and _column in range(kngsClmn - 1, kngsClmn + 2):
+ raise ChessException("kings")
+ else:
+ kngsRow = _row
+ kngsClmn = _column
+ if i.upper() == 'P':
+ if _row == 1 or _row == 8:
+ raise ChessException("pawns")
+ continue
+ def get_white_score(self):
+ for i in self.fen:
+ if i.isupper() == True:
+ self._wscore.append(i)
+ return Score(self._wscore)
+ def get_black_score(self):
+ for i in self.fen:
+ if i.islower() == True:
+ self._bscore.append(i)
+ return Score(self._bscore)
+ 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()
+ def __repr__(self):
+ return self.fen
+ def __len__(self):
+ cntfig = 0
+ lst = range(1, 11)
+ nums = [format(x, '') for x in lst]
+ for i in self.fen:
+ if i not in nums and i!='/':
+ cntfig += 1
+ return cntfig
+ def __getitem__(self, pos):
+ column = 0
+ row = 1
+ lst = range(1, 11)
+ nums = [format(x, '') for x in lst]
+ letters = ["A", "B", "C", "D", "E", "F", "G", "H" ]
+ letter = letters.index(pos[0].upper()) + 1
+ for i in self.fen:
+ if i in nums:
+ column += int(i)
+ else:
+ column += 1
+ if i == '/' :
+ row += 1
+ column = 0
+ if column == letter and row == int(pos[1]):
+ return i
+
+
+class ChessScore():
+ def __init__(self, figures):
+ self.__figures = figures
+ self.Allpoints = Score(self.__figures)
+ def __add__(self, otherChessScore):
+ return self.Allpoints + otherChessScore.Allpoints
+ def __sub__(self, otherChessScore):
+ return self.Allpoints - otherChessScore.Allpoints
+ def __eq__(self, otherChessScore):
+ return self.Allpoints == otherChessScore.Allpoints
+ def __ne__(self, otherChessScore):
+ return self.Allpoints != otherChessScore.Allpoints
+ def __le__(self, otherChessScore):
+ return self.Allpoints <= otherChessScore.Allpoints
+ def __lt__(self, otherChessScore):
+ return self.Allpoints < otherChessScore.Allpoints
+ def __gt__(self, otherChessScore):
+ return self.Allpoints > otherChessScore.Allpoints
+ def __int__(self):
+ return self.Allpoints
+