初心者にとっては、これは三目並べの単純なバージョンです。私は困難を伴うように設計されたAIを作成中であり、コード内にAI(ランダム化)の部分的なコードがあります。その機能は無視してください。しかし、私の主な難しさは、ボード上での動きを正しく印刷することです。何らかの理由で、XまたはOのどちらになりたいかを選択すると、自動的にXに送信されます。さらに、位置A以外を選択すると、位置AにXが出力されます。誰かが私のコーディングのどこで私が間違っていたのかを正確に教えてくれる助けをくれたらいいのにと思います。別の言い方をすれば、私のゲームをより明確で簡単にするために、移動が行われた後にボードとボード2を並べて印刷したいと思います。これは、どのムーブが利用可能かを示すためのものであるため、ムーブAとBが実行された場合、それらはボードに表示されません。
print "**********************"
print "*THE GAME WILL BEGIN.*"
print "**********************"
import random
indx=0
move_storage=[]
move=["","","","","","","","",""]
#**************************************************
# This is the original board *
#**************************************************
def board():
print "This is the tictactoe board we will be playing on"
print " | | "
print " A | B | C "
print " | | "
print "------------------------------"
print " | | "
print " D | E | F "
print " | | "
print "------------------------------"
print " | | "
print " G | H | I "
print " | | "
board()
#****************************************************
#This is the board where the moves will be displayed*
#****************************************************
def board2(move):
print " ",move[0]," | ",move[1]," | ",move[2]," "
print " | | "
print " ----------------------- "
print " | | "
print " ",move[3]," | ",move[4]," | ",move[5]," "
print " | | "
print " ----------------------- "
print " | | "
print " ",move[6]," | ",move[7]," | ",move[8]," "
#This function will store all of the moves inputed.
def movestorage(move_storage, move):
move_storage= move_storage + [move]
#This function will randomize the computer's move
def computer_move():
move_random=random.randint(1,9)
move[move_random]=computer_choice
movestorage(move_storage, move)
player=raw_input("Would you like to play as x or o-->")
player_order=raw_input("Would you like to go first,y/n?-->")
while indx==0:
if 'x' or 'X' == player:
player_choice="X"
computer_choice="O"
if 'y' or 'Y' in player_order:
print
elif 'n' or 'N' in player_order:
print
print "The computer will go first, press ENTER to see the computers turn"
elif 'o' or 'O' == player:
player_choice="O"
computer_choice="X"
if 'y' or 'Y' in player_order:
print
elif 'n' or 'N' in player_order:
print
print "The computer will go first, press ENTER to see the computers turn"
x=0
while 2>x: #This is where the player decides where he wants to go
choice=raw_input("Choose where you would like to move-->")
if choice == 'a' or 'A':
move[0]=player_choice
movestorage(move_storage, move)
elif choice == 'b' or 'B':
move[1]=player_choice
movestorage(move_storage, move)
elif choice == 'c' or 'C':
move[2]=player_choice
movestorage(move_storage, move)
elif choice == 'd' or 'D':
move[3]=player_choice
movestorage(move_storage, move)
elif choice == 'e' or 'E':
move[4]=player_choice
movestorage(move_storage, move)
elif choice == 'f' or 'F':
move[5]=player_choice
movestorage(move_storage, move)
elif choice == 'g' or 'G':
move[6]=player_choice
movestorage(move_storage, move)
elif choice == 'h' or 'H':
move[7]=player_choice
movestorage(move_storage, move)
elif choice == 'i' or 'I':
move[8]=player_choice
movestorage(move_storage, move)
board2(move)
また、私はきちんとしたためにいくつかの空白の印刷ステートメントを持っています、それらは間違いではありません。