Othello game

Hi i'm deeeeeesperate for some help. I'm trying to make a othello game but i can't get the damn grid to show. The grid.UpdateBoard(Board.BoardState); is meant to place the grid onto the Othello Game window as shown in the picture. Does someone know what might be wrong and able to help? https://github.com/aljomatrix/Assignment2Repository
No description
20 Replies
FusedQyou
FusedQyouβ€’3w ago
Any errors at the top of the window when you proceed with the code?
Merineth πŸ‡ΈπŸ‡ͺ
No no errors at all
FusedQyou
FusedQyouβ€’3w ago
Also note with the breakpoint being on the operation, UpdateBoard is not called yet
Merineth πŸ‡ΈπŸ‡ͺ
I have been trying to troubleshoot for a couple of hours now so the code has been changed I can push the changes to github The problem mainly relies in GameGrid as it's not displaying the pieces correctly. However it is doing the game correct in the background as far as i can tell. I pushed the changes This is so complicated to me 😭 i have no idea how to fix it
Merineth πŸ‡ΈπŸ‡ͺ
It's actually going through the loop and playing the game (because both player1 and player2 currently plays as AI) in the background. But nothing changes visually. Not even the pieces show up.
public void UpdateBoard(Disk[,] boardState)
{
// Loop through the board state (2D array) and place pieces
for (int row = 0; row < 8; row++)
{
for (int column = 0; column < 8; column++)
{
var tile = BoardGrid.Children[row * 8 + column] as Border; // Get the corresponding tile

// Find the Ellipse inside the Border
var ellipse = tile?.Child as Ellipse;

if (boardState[row, column] == Disk.White)
{
ellipse.Fill = Brushes.White;
}
else if (boardState[row, column] == Disk.Black)
{
ellipse.Fill = Brushes.Black;
}
else
{
ellipse.Fill = Brushes.Transparent; // Empty cell
}
}
}
}
public void UpdateBoard(Disk[,] boardState)
{
// Loop through the board state (2D array) and place pieces
for (int row = 0; row < 8; row++)
{
for (int column = 0; column < 8; column++)
{
var tile = BoardGrid.Children[row * 8 + column] as Border; // Get the corresponding tile

// Find the Ellipse inside the Border
var ellipse = tile?.Child as Ellipse;

if (boardState[row, column] == Disk.White)
{
ellipse.Fill = Brushes.White;
}
else if (boardState[row, column] == Disk.Black)
{
ellipse.Fill = Brushes.Black;
}
else
{
ellipse.Fill = Brushes.Transparent; // Empty cell
}
}
}
}
This is the actual part that updates the pieces on the board
Merineth πŸ‡ΈπŸ‡ͺ
And once it gets to row 4 column 5 it actually doers fill an ellipse with the brush black
No description
Merineth πŸ‡ΈπŸ‡ͺ
But nothing is showing ? I pushed my changes but i'm simply gonna wait to see if someone is able to help me. Lowkey desperate for help..
Sossenbinder
Sossenbinderβ€’3w ago
Okay, so I know almost nothing about Desktop programming, but I gave it a shot and pulled your repo Your issue isn't a brush or similar Your issue is that your game loop is entirely blocking and doesn't allow the main thread to repaint I tried to exchanged some parts for an async-await waiting for a player turn and now the rendering works as you described
Merineth πŸ‡ΈπŸ‡ͺ
@Sossenbinder really?! I'd love to see what you did for it to work i've been plagued with it for the past 3 days 😭
Sossenbinder
Sossenbinderβ€’3w ago
Sure, one sec https://github.com/aljomatrix/Assignment2Repository/commit/3b07dc93b5cec392ce3faafcd9ea4aceaafc2555 Forked your repo Note that I'm not a desktop programmer though, so I'd probably check with the #gui peeps what the preferred way of doing this would be Just wanted to verify the problem is you keeping the main loop hostage haha
Merineth πŸ‡ΈπŸ‡ͺ
I'm a bit of a beginner to github. How would i test the code? Or merge it to main perhaps Or would i need a ned repo for that?
Sossenbinder
Sossenbinderβ€’3w ago
Ah, I could probably also create a pull request to yours, but I'm about to head to bed so I won't manage to do so anymore today You can probably apply the changes by hand just to explore the result, shouldn't be too bad
Sossenbinder
Sossenbinderβ€’3w ago
No description
Sossenbinder
Sossenbinderβ€’3w ago
If you set the layout to "Split" it's a bit clearer to see both states Should be quick to apply that way
Merineth πŸ‡ΈπŸ‡ͺ
aaah i can see them!!!!!!!!! <3 i fucking love you
Merineth πŸ‡ΈπŸ‡ͺ
Now i just have to clean up so that the game works properly
No description
Merineth πŸ‡ΈπŸ‡ͺ
you are my literal saviour thank you so much
Sossenbinder
Sossenbinderβ€’3w ago
Gl Make sure to read up on WPF threading model and why blocking the main thread causes that issue
Merineth πŸ‡ΈπŸ‡ͺ
will do! !solved

Did you find this page helpful?