あなたのコードを書き直すことができれば:
for (lo = 0; lo < 9; lo++){
if (hi[lo] == " "){
hi[lo] = "o";
break;
}
}
そうです、「o」が 1 つ挿入されます。
質問はなんですか?
編集:三目並べゲームを作成しようとしているので、全体的な疑似コードをいくつか提案させてください:
repeat
ask user where they want to place an "x" (i.e. get a number from 0 to 8)
if that square is not blank, say so and ask again
else put the "x" in the square
If this completes a row, column, or diagonal, exit saying "You win!"
-> enter the loop here if you are making the first move
then find out where to put an "o". You do this by looking at all unoccupied squares.
for each unoccupied square
look at the row, column, and diagonal it is on
if putting an "o" there would make you the winner, give it a really high score
if putting an "o" there would block the user from winning, give it a high score
if putting an "o" there would mean that you could win on the following move, give it a medium score
Otherwise give it a score that is the number of rows, columns, and diagonals it could possibly tie up
end for each
Then put the "o" on the highest-scored square (or one of the highest-scored squares if there are more than one)
If you completed a row, column, or diagonal, exit saying "I win!".
If you can't find a square to mark, exit saying "I give up".
end repeat
これよりも短いバージョンがあると確信しています。それは私の頭のてっぺんから外れています。