How to make the cursor move for the Comp -Tc Tac Toe
How to make the cursor move for the Comp -Tc Tac Toe
hi Chilli ,
I could manage coding a smart AI for the computer. But i am not able to make the cursor move.
Here is the coding did. I end up crashing the whole program saying ' Unhandled exception at 0x00111949 in Chili DirectX Framework.exe: 0xC0000005: Access violation writing location 0x0542fea8. '.
void Game::DoAITurnRand()
{
AIGetNextMoveRand();
CursorMove();
SetSquareState( AIMove ,activePlayer );
EndTurn();
}
void Game::CursorMove()
{
const int baseX=250;
const int baseY=150;
const int squareSize = 100;
int currentposX=cursorX, currentposY=cursorY, TargetposX = AIMove%3 , TargetposY=AIMove/3;
while(currentposY>TargetposY )
{
cursorY=cursorY-1;
DrawCursor( baseX + cursorX * squareSize,baseY + cursorY * squareSize);
}
while(currentposY<TargetposY )
{
cursorY=cursorY+1;
DrawCursor( baseX + cursorX * squareSize,baseY + cursorY * squareSize);
}
while(currentposX>TargetposX )
{
cursorX=cursorX-1;
DrawCursor( baseX + cursorX * squareSize,baseY + cursorY * squareSize);
}
while(currentposX<TargetposX )
{
cursorX=cursorX+1;
DrawCursor( baseX + cursorX * squareSize,baseY + cursorY * squareSize);
}
}
Please tell me where am i going wrong. And even though if i make this logic correct, i think that the computer would execute those while loops so fast, that i cannot actually see the cursor travel to its destination. Right??
I could manage coding a smart AI for the computer. But i am not able to make the cursor move.
Here is the coding did. I end up crashing the whole program saying ' Unhandled exception at 0x00111949 in Chili DirectX Framework.exe: 0xC0000005: Access violation writing location 0x0542fea8. '.
void Game::DoAITurnRand()
{
AIGetNextMoveRand();
CursorMove();
SetSquareState( AIMove ,activePlayer );
EndTurn();
}
void Game::CursorMove()
{
const int baseX=250;
const int baseY=150;
const int squareSize = 100;
int currentposX=cursorX, currentposY=cursorY, TargetposX = AIMove%3 , TargetposY=AIMove/3;
while(currentposY>TargetposY )
{
cursorY=cursorY-1;
DrawCursor( baseX + cursorX * squareSize,baseY + cursorY * squareSize);
}
while(currentposY<TargetposY )
{
cursorY=cursorY+1;
DrawCursor( baseX + cursorX * squareSize,baseY + cursorY * squareSize);
}
while(currentposX>TargetposX )
{
cursorX=cursorX-1;
DrawCursor( baseX + cursorX * squareSize,baseY + cursorY * squareSize);
}
while(currentposX<TargetposX )
{
cursorX=cursorX+1;
DrawCursor( baseX + cursorX * squareSize,baseY + cursorY * squareSize);
}
}
Please tell me where am i going wrong. And even though if i make this logic correct, i think that the computer would execute those while loops so fast, that i cannot actually see the cursor travel to its destination. Right??
Believe. Become.
Re: How to make the cursor move for the Comp -Tc Tac Toe
Can you upload the code after cleaning it? Read the READ THIS FIRST post.
The reason why you cant see the cursor moving is not because it's so fast, but because you don't present the frame in between. So basically the loop executes withing a frame, so you won't see it moving at all.
The reason why you cant see the cursor moving is not because it's so fast, but because you don't present the frame in between. So basically the loop executes withing a frame, so you won't see it moving at all.
ʕ •ᴥ•ʔ
Re: How to make the cursor move for the Comp -Tc Tac Toe
Okay. Here is the solution attached. And yes you are right about the loop. Now how do make the cursor move slow. like should i be using sleep() or something like that ??
Thanks.
Thanks.
- Attachments
-
- Chili DirectX Framework Tic Tac Toe-vs Smart moving Computer.rar
- (35.73 KiB) Downloaded 128 times
Believe. Become.
Re: How to make the cursor move for the Comp -Tc Tac Toe
Sleep will stall the whole program so it's not the best solution.
You need to make it so that the cursor is moved, and then the game just does nothing for 30 or so frames, and then it is moved again. Not sleeping, but just running through the Game::Go function without changing anything on the screen.
You need to make it so that the cursor is moved, and then the game just does nothing for 30 or so frames, and then it is moved again. Not sleeping, but just running through the Game::Go function without changing anything on the screen.
Chili
Re: How to make the cursor move for the Comp -Tc Tac Toe
I am not able to understand properly. Can you please attach the solution for it.
Believe. Become.
Re: How to make the cursor move for the Comp -Tc Tac Toe
well.. now i got the cursor moving to the correct target position. but it moves way too fast. it moves one box every single frame. so its kinda fast. how do i make it move slow..
i have attached my updated coding.
i have attached my updated coding.
- Attachments
-
- Chili DirectX Framework Tic Tac Toe-vs Smart moving Computer.rar
- (36.03 KiB) Downloaded 150 times
Believe. Become.
Re: How to make the cursor move for the Comp -Tc Tac Toe
You could make a variable "FrameCount" then each frame you add "FrameCount ++;"
Then where ever your movement code is:
"if (FrameCount == 30) /* ~Half a second */ {FrameCount = 0; /* Your movement code */}
Then where ever your movement code is:
"if (FrameCount == 30) /* ~Half a second */ {FrameCount = 0; /* Your movement code */}
ʕ •ᴥ•ʔ