Created
October 25, 2016 23:48
-
-
Save cyberlex404/39d0aa07bb37830c43721dbe4fb03b7a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| allstep = {1: {'x':-1, 'y': 2}, | |
| 2: {'x':1, 'y': 2}, | |
| 3: {'x':2, 'y': 1}, | |
| 4: {'x':2, 'y': -1}, | |
| 5: {'x':1, 'y': -2}, | |
| 6: {'x':-1, 'y': -2}, | |
| 7: {'x':-2, 'y': -1}, | |
| 8: {'x':-2, 'y': 1}, | |
| } | |
| liters = {1:'A', 2:'B', 3:'C', 4:'D', 5:'E', 6:'F', 7:'G', 8:'H'} | |
| print('Введите позицию коня в формате БукваЦифра {A1 B5 H10}') | |
| point = input() | |
| StepsList = [] | |
| def search(point): | |
| print(point) | |
| def littoint(point): | |
| lit = point[0] | |
| #print(lit, end='<<lit\n') | |
| inv_liters = {v: k for k, v in liters.items()} | |
| return inv_liters.get(lit) | |
| def numtolit(num): | |
| return liters.get(num) | |
| def checkstep(x, y, i, j): | |
| n = x + i # ход по X | |
| m = y + j # ход по Y | |
| if ((n <= 8) and (n >=1)) and((m <= 8) and (m >=1)): # остались в рамках доски? | |
| return True | |
| else: return False | |
| # получаем текущую позицию коня | |
| Py = int(point[1]) | |
| Px = littoint(point) | |
| for current in allstep: #перебираем словарь ходов | |
| move = allstep[current] #получаем элемент из словаря | |
| x = move['x'] #получаем ход по X | |
| y = move['y'] #получаем ход по Y | |
| if checkstep(Px, Py, x, y): #проверяем останется ли конь в рамках доски | |
| lit = numtolit(Px+x) #Получаем букву | |
| num = str(Py+y) # получаем цифру и переводим в строку | |
| name = lit + num # получаем новую ячейку в рамках доски | |
| StepsList.append(name) # Добавляем проверенную ячейку в список доступных ходов | |
| print('Коню доступно ходов:', len(StepsList) ) # выводим сколько всего в списке элементов (ходов) | |
| for elem in StepsList: #перебираем список ходов | |
| print(point, elem, sep=' => ') #выводим в формате "из => в" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment