1. Tictactoe 게임 (ver_5)
- 기능 : 2인 플레이 기능, 중복 위치 선택 방지기능
- Tictactoe 게임 (ver_6) 예정 기능 : 위치 선택 필터링기능(정규식사용), 1인 플레이 기능
the_board = {
'top-L': ' ', 'top-M': ' ', 'top-R': ' ',
'mid-L': ' ', 'mid-M': ' ', 'mid-R': ' ',
'low-L': ' ', 'low-M': ' ', 'low-R': ' '
}
def print_board(board):
top_list = []
mid_list = []
low_list = []
for k, v in board.items():
if 'top' in k:
top_list.append(v)
if 'mid' in k:
mid_list.append(v)
if 'low' in k:
low_list.append(v)
top_str = '|'.join(top_list)
mid_str = '|'.join(mid_list)
low_str = '|'.join(low_list)
print('-------------------------------------------')
print('{}\n-+-+-\n{}\n-+-+-\n{}'.format(top_str, mid_str, low_str))
print('-------------------------------------------')
turn = 'X'
board_location = list(the_board.keys())
while True:
if ' ' not in list(the_board.values()):
print("게임이 종료되었습니다")
break
print_board(the_board)
print("다음 상대의 차례! %s . 어느 위치로 이동하시겠습니까?" % turn)
move = int(input()) - 1
key_move = board_location[move]
if the_board[key_move] != ' ':
print('다시 입력하세요!')
continue
the_board[key_move] = turn
if turn == 'X':
turn = '0'
else:
turn = 'X'