Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- os.system('cls')
- #saisie des indices du reine
- def saisie():
- while 1:
- x = input()
- if x.isdigit():
- x = int(x)
- if x >= 0 and x < 8:
- return x
- else:
- print("! valeur doit etre entre 0 et 7")
- else:
- print('! valeur doit etre entre un entier')
- #remplir la table par '-'
- def init_board():
- board = []
- for i in range(8):
- sub_board = []
- for j in range(8):
- sub_board.append('-')
- board.append(sub_board)
- return board
- #afficher la table
- def board_printer(board):
- print('-' * 27)
- #le role du variable 'start' est de connaitre si on
- #est sur le debut du ligne pour ajouter le '|'
- start = 1
- for sub_board_one in board:
- for sub_board_two in sub_board_one:
- if start:
- print('|', sub_board_two, ' ', end = '')
- start = 0
- else:
- print(sub_board_two, ' ', end = '')
- print('|')
- start = 1
- print('-' * 27)
- #remplir l'axe de X et Y d'indice du reine
- def plus(board,l,c):
- for i in range(0,8):
- if not i == c:
- board[l][i] = 'X'
- for i in range(0,8):
- if not i == l:
- board[i][c] = 'X'
- #remplir le diagonal d'indice du reine
- def diagonal(board,l,c):
- #top left
- l1,c1 = l-1,c-1
- while l1 >= 0 and c1 >= 0:
- board[l1][c1] = 'X'
- l1 -= 1
- c1 -= 1
- #right down
- l1,c1 = l+1,c+1
- while l1 < 8 and c1 < 8:
- board[l1][c1] = 'X'
- l1 += 1
- c1 += 1
- #top right
- l1,c1 = l-1,c+1
- while l1 >= 0 and c1 < 8:
- board[l1][c1] = 'X'
- l1 -= 1
- c1 += 1
- #down left
- l1,c1 = l+1,c-1
- while l1 < 8 and c1 >= 0:
- board[l1][c1] = 'X'
- l1 += 1
- c1 -= 1
- def main():
- print("saisie N° du ligne")
- l = saisie()
- print("saisie N° du colonne")
- c = saisie()
- os.system('cls')
- board = init_board()
- board[l][c] = 'R'
- plus(board,l,c)
- diagonal(board,l,c)
- board_printer(board)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement