참고 : 필자는이 작업을 진행하면서 최신으로 업데이트하고 있습니다. 코드에 추가했는지 여부를 알려주는 주석을 추가합니다. 아무런 코멘트가 없으므로 누구나 혼란 스러울 것입니다. 그리고 저에게 투표 한 사람 중 누구든지 가능한 한 많은 정보를 제공 할 것입니다. 진정하다.MATLAB 승/도우미 함수에서 Tic-Tac-Toe에 대한 이동 및 결과 결정
꽤 긴 제목이지만이 문제에 필요한 모든 것을 요약합니다. 나는 3x3 셀 형태의 틱택 (tic-tac-toe) 보드와 누구의 이동인지를 알려주는 문자열을 받았습니다 (플레이어 X 또는 플레이어 O). 가능한 이동이 가능한지와 그 이동의 결과가 무엇인지 나열하는 2xN 셀을 필요로합니다. 예를 들어, 플레이어는 플레이어 X이고, 내 보드는 다음과 같습니다
{ 'x' 'o' 'x'
'o' 'x' 'o'
'o' ' ' ' ' }
그럼 내 옵션 반점이 항상 공백으로 표시됩니다
{ 'x' 'o' 'x' {'x' 'o' 'x'
'o' 'x' 'o' 'o' 'x' 'o'
'o' 'x' ' '} 'o' ' ' 'x'}
'Your move, player O.' 'Player X Wins!' }
공백이 있습니다.
Helper Function Name: moveEvaluator
Helper Function Inputs (2): - (char) A 3x3 character array representing
a tic tac toe board, after a move
has been made.
- (char) A single character of the the
player that just moved.
Helper Function Outputs (1): - (char) A string indicating the outcome
of the turn.
The helper function moveEvaluator takes in a 3x3 character array of a
tic tac toe board after a move has been made, with spaces used to
represent the empty spaces on the board, and a single character of the
player who just went. This 2nd input will be a string of either 'x' or
'o'. This helper function will then output the outcome of that turn: if
it was player X's turn, then the two possible outcomes are 'Player X
Wins!' or 'Your turn, player O.' Similarly, if it was player O's turn,
then the two possible outcomes are 'Player O Wins!' or 'Your turn,
player X.'
그래서 기본적으로 나를 위해 반 제 기능을 수행합니다 지금은이 문제에 대해,이처럼 보이는 'moveEvaluater'라는 도우미 기능을 부여했습니다. 나는 호키이 작업 덕분에 갖고있는 것 같다 :)
function[Move_Choices] = ticTacToeTurn(Board, str)
charBoard = reshape(char(Board) , 3 , 3) ;
PlayerSymbol = str ;
% Find the indices of possible move
Move_Choices = find(ismember(Board, ' '));
% // count them
nChoices = numel(Move_Choices) ;
% // pre-allocate output
outcome = cell(nChoices,1) ;
Options = '';
Strings = '';
% // Get outcome for each possible postition
for iSlot = 1:nChoices
PossibleBoard = charBoard ; % // copy the initial board
PossibleBoard(Move_Choices(iSlot)) = PlayerSymbol;% // Add an 'x' at one of the empty position
disp(PossibleBoard) ; % display the currently played board/optional, just for your information
PossibleBoard = char(PossibleBoard);
outcome = moveEvaluator(PossibleBoard, str);
Strings = [Strings {outcome}];
end
for iSlot = 1:nChoices
PossibleBoard = charBoard ; % // copy the initial board
PossibleBoard(Move_Choices(iSlot)) = PlayerSymbol;% // Add an 'x' at one of the empty position
disp(PossibleBoard) ; % display the currently played board/optional, just for your information
PossibleBoard = cellstr(PossibleBoard);
Options = [Options, {PossibleBoard}];
end
Move_Choices = [Options;Strings]; %// Here's my issue. This outputs a cell, but the cellstr function separated the x's and o's into cells of three. I need each spot to be their own cell :/
end
나는 그냥 둘, 하나의 슬롯에 하나의 X를 입력해야합니다. 또한 여기에서 도우미 함수를 사용하여 가능한 문자열 옵션이 무엇인지 출력하는 방법을 알아야합니다.
Testcases:
board1 = { 'x' 'o' 'x'
'o' 'x' 'o'
'o' ' ' ' ' }
move1 = 'x'
possibleMoves1 = ticTacToeTurn(board1,move1)
이 제공해야하는 것 같습니다 × 2 셀 수 : 그래서 너무 확실하지 않다 나는 평가자 기능에 대한 코드를 살펴하려
Cell (1,1) This is a cell inside a cell. All of the 'x' and 'o's are a separate cell
{'x''o' 'x'
'o' 'x' 'o'
'o' 'x' ' '}
Cell (2,1) looks is the string that says "Your move, Player O"
Cell (1,2) Should be
{ 'x' 'o' 'x'
'o' 'x' 'o'
'o' ' ' 'x'}
Cell (2, 2) looks is the string that says "Player X wins!'
,하지만 분명히 AP 파일 무엇 할 것. 어떤 도움을 주시면 감사하겠습니다 :) 내가 무엇이든 놓친다면 알려주지. 모두가되어야합니다.
숙제이기 때문에 나는 많은 것을 밝히지 않을 때 조심해야한다. (선생님도 알고있다.) 그러나 나는 당신이 가능한 모든 이사회에 관심이 없다고 생각하지만 다음 이사 만 할 것입니다. 그러나 하나 또는 두 개의 루프를 사용하는 것을 고려해야 할 수도 있습니다 (matlab에서는 열 단위 인덱스를 사용합니다. 즉, 보드 {5}를 입력하면 요소 보드 {2,2}를 얻을 수 있습니다. 그렇지 않으면 2 for 루프가 필요합니다). 보드를 저장하려면 셀 배열이나 구조체 배열을 사용하십시오.(모든 요소는 가능한 이동이 가능한 보드 임)에 대해 컨테이너에 요소를 추가합니다. – patrik
@patrik 선생님은 숙제를 확인하지 않고 TA는 신경 쓰지 않습니다. 코드의 일부가 제 것이면 부주의 할 수 있습니다. 그 말로는 칼럼 색인 작성을 이해합니다. 내 보드를 문자열로 변환하여 쉽게 변경할 수있게했습니다. 나는 for 루프와 함께 끔찍하지만, while 루프를 사용하는 방법을 잘 모르겠습니다. 또는 한 번에 하나씩 요소를 추가하고 연속 된 순서로 요소를 추가하지 않는 방법 (모든 공간을 채우는 곳). –
@patrik 지금 당장은 도우미 기능을 사용하고 있습니다. 결국 for 루프와 while 루프로 장난감을 가지고 보드를 작동시킬 수는 있지만 실제 루프를 위해 나를 던진 헬퍼 함수입니다. –