Othello Reversi game

I'm supposed to create an entire othello also called Reversi game from scratch in C# WPF application. I*m gonna be completely and utterly honest, i have no idea what to do and this assignment is way to hard for me. It's about 6+ months overdue and it's supposed to be done in groups of 3+ but the ones in my group just hopped of the course. I'm unironically desperate for some help and would really appreciate it if someone had some time during the day to help me wrap this up. I've done most of the stuff already but i need help with the main logic. I'm desperate.
1064 Replies
TheRanger
TheRangerβ€’2mo ago
what did you do so far?
Merineth πŸ‡ΈπŸ‡ͺ
I'll share it, one moment
Merineth πŸ‡ΈπŸ‡ͺ
GitHub
GitHub - aljomatrix/Assignment2Repository
Contribute to aljomatrix/Assignment2Repository development by creating an account on GitHub.
Merineth πŸ‡ΈπŸ‡ͺ
this is the repo, i think you should have access to it
Merineth πŸ‡ΈπŸ‡ͺ
I've created the essential windows, their corresponding popups
No description
No description
Merineth πŸ‡ΈπŸ‡ͺ
However all that remains is the logic part I still don't know how to set the initial board pieces for example
TheRanger
TheRangerβ€’2mo ago
do u have the images of those pieces?
Merineth πŸ‡ΈπŸ‡ͺ
No. but i assume i can use some png photo online?
TheRanger
TheRangerβ€’2mo ago
or just draw it on MS Paint or you could draw ellipses
Merineth πŸ‡ΈπŸ‡ͺ
Yeah i read about the ellipses but i don't know how to make them so i think png is easier for me?
TheRanger
TheRangerβ€’2mo ago
there are tutorials on how to make ellipses in wpf
Merineth πŸ‡ΈπŸ‡ͺ
Could i use something like this perhaps?
TheRanger
TheRangerβ€’2mo ago
sure
Merineth πŸ‡ΈπŸ‡ͺ
ok i have added them into my project
TheRanger
TheRangerβ€’2mo ago
create Images Controls for your pieces and place them on your board or do u start with an empty board? im not familiar with the game
Merineth πŸ‡ΈπŸ‡ͺ
When i click new game, the prompts for the player names comes in. You inpuit those and then the game start when you hit ok That's when the initial pieces should be placed So in SetupGameDialog.xaml.cs
TheRanger
TheRangerβ€’2mo ago
yeah
Merineth πŸ‡ΈπŸ‡ͺ
private void OKButton_Click(object sender, RoutedEventArgs e)
{
// Capture the player names and computer flag
Player1Name = Player1NameTextBox.Text;

// Check if Player 2 is a computer
IsPlayer2Computer = (bool)IsPlayer2ComputerCheckBox.IsChecked;

// If Player 2 is a computer, automatically set the name to "Computer"
if (IsPlayer2Computer)
{
Player2Name = "Computer";
}
else
{
// Otherwise, get Player 2's name from the TextBox
Player2Name = Player2NameTextBox.Text;
}

// Validation: Ensure both player names are provided (except Player 2 if it's a computer)
if (string.IsNullOrEmpty(Player1Name) || (string.IsNullOrEmpty(Player2Name) && !IsPlayer2Computer))
{
MessageBox.Show("Please enter names for both players.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

// Set the DialogResult to true and close the dialog if everything is valid
this.DialogResult = true;
this.Close();
}
private void OKButton_Click(object sender, RoutedEventArgs e)
{
// Capture the player names and computer flag
Player1Name = Player1NameTextBox.Text;

// Check if Player 2 is a computer
IsPlayer2Computer = (bool)IsPlayer2ComputerCheckBox.IsChecked;

// If Player 2 is a computer, automatically set the name to "Computer"
if (IsPlayer2Computer)
{
Player2Name = "Computer";
}
else
{
// Otherwise, get Player 2's name from the TextBox
Player2Name = Player2NameTextBox.Text;
}

// Validation: Ensure both player names are provided (except Player 2 if it's a computer)
if (string.IsNullOrEmpty(Player1Name) || (string.IsNullOrEmpty(Player2Name) && !IsPlayer2Computer))
{
MessageBox.Show("Please enter names for both players.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

// Set the DialogResult to true and close the dialog if everything is valid
this.DialogResult = true;
this.Close();
}
Meaning this part It takes the two names from the players if it's an AI it's default set to "Computer" Maybe it's easier to set the board state before this? On the GameWindow.xaml.cs perhaps?
TheRanger
TheRangerβ€’2mo ago
is the board form already open in the background when its asking for your name?
Merineth πŸ‡ΈπŸ‡ͺ
Yes i think so GameWindow.xml is the first window that starts when the program starts
TheRanger
TheRangerβ€’2mo ago
i assume the form on the left is the game window?
Merineth πŸ‡ΈπŸ‡ͺ
Yes
TheRanger
TheRangerβ€’2mo ago
i think its fine if it asks for your names after u create the board
Merineth πŸ‡ΈπŸ‡ͺ
I think so too
Merineth πŸ‡ΈπŸ‡ͺ
The gameboard has a grid which i made
No description
Merineth πŸ‡ΈπŸ‡ͺ
So the 4 pieces should initially go to D4, E4, D5, E5
TheRanger
TheRangerβ€’2mo ago
yeah
Merineth πŸ‡ΈπŸ‡ͺ
public partial class GameWindow : Window
{
private GameManager gameManager;
public GameWindow()
{
InitializeComponent();
InitializeStartingPieces();
}
private void InitializeStartingPieces()
{
PlacePiece(3, 3, "white_piece.png");
PlacePiece(4, 4, "white_piece.png");
PlacePiece(3, 4, "black_piece.png");
PlacePiece(4, 3, "black_piece.png");
}

private void PlacePiece(int row, int col, string pieceImage)
{

}
public partial class GameWindow : Window
{
private GameManager gameManager;
public GameWindow()
{
InitializeComponent();
InitializeStartingPieces();
}
private void InitializeStartingPieces()
{
PlacePiece(3, 3, "white_piece.png");
PlacePiece(4, 4, "white_piece.png");
PlacePiece(3, 4, "black_piece.png");
PlacePiece(4, 3, "black_piece.png");
}

private void PlacePiece(int row, int col, string pieceImage)
{

}
Maybe something like this? I assume i have to call the method in GameWindow?
TheRanger
TheRangerβ€’2mo ago
sure
Merineth πŸ‡ΈπŸ‡ͺ
Having a hard time placing them tho
TheRanger
TheRangerβ€’2mo ago
how so? i think i see what u mean
Merineth πŸ‡ΈπŸ‡ͺ
I'm not familiar with how images work
TheRanger
TheRangerβ€’2mo ago
u might want to create a method called CellToBoardPosition what is the size of your image's board?
Merineth πŸ‡ΈπŸ‡ͺ
You mean the entirety of the green board?
TheRanger
TheRangerβ€’2mo ago
it seems to be 400,400 correct?
Merineth πŸ‡ΈπŸ‡ͺ
Yes
TheRanger
TheRangerβ€’2mo ago
if you divide 400 by 8, since there are 8 rows and 8 columns
Merineth πŸ‡ΈπŸ‡ͺ
400x400 based of the GameGrid.xaml
TheRanger
TheRangerβ€’2mo ago
a cell's size is 50x50
Merineth πŸ‡ΈπŸ‡ͺ
yeah
TheRanger
TheRangerβ€’2mo ago
u could start by creating that method in your board class or CellToPixelPosition
Merineth πŸ‡ΈπŸ‡ͺ
ok
private void CellToPixelPosition()
{

}
private void CellToPixelPosition()
{

}
TheRanger
TheRangerβ€’2mo ago
u can guess what it indicates it obviously need parameters
Merineth πŸ‡ΈπŸ‡ͺ
Convert the picture to 50x50?
TheRanger
TheRangerβ€’2mo ago
ur board is 8x8 cells, right?
Merineth πŸ‡ΈπŸ‡ͺ
yes
TheRanger
TheRangerβ€’2mo ago
its purpose is to give which position in the image this cell is
Merineth πŸ‡ΈπŸ‡ͺ
I'm not sure i understand
TheRanger
TheRangerβ€’2mo ago
lets grab B2 B2 is 1,1 in cell dimensions, right?
Merineth πŸ‡ΈπŸ‡ͺ
Yes
TheRanger
TheRangerβ€’2mo ago
ok in image dimension, where is it?
Merineth πŸ‡ΈπŸ‡ͺ
100x100?
TheRanger
TheRangerβ€’2mo ago
thats the bottom right of it
Merineth πŸ‡ΈπŸ‡ͺ
75x75
TheRanger
TheRangerβ€’2mo ago
thats its middle im not sure where the pivot of image control is in wpf but lets assume its the center, then yes it would be 75x75
Merineth πŸ‡ΈπŸ‡ͺ
Can't we place the images into 3.3 ? 3.3, 3.4, 4.3 and 4.4 Those are the grid positions for the 4 middle starting positions
TheRanger
TheRangerβ€’2mo ago
ofc u can so ur parameters methods should be like this
public (int x,int y) CellToPixelPosition(int row, int col)
{

}
public (int x,int y) CellToPixelPosition(int row, int col)
{

}
u just need to do some math to convert for example 1,1 to 75,75
Merineth πŸ‡ΈπŸ‡ͺ
Oh ok
private void CellToPixelPosition(int row, int col)
{
int cellWidth = 50;
int cellHeight = 50;

int x = col * cellWidth;
int y = row * cellHeight;
}
private void CellToPixelPosition(int row, int col)
{
int cellWidth = 50;
int cellHeight = 50;

int x = col * cellWidth;
int y = row * cellHeight;
}
TheRanger
TheRangerβ€’2mo ago
ah the pivot is top left by default mate ur cell is 50x50 not 75x75 if the pivot of the image is in the center u would add 25 after u multiply yeah but i guess we dont need that i assume someone created those classes and methods in ur projects and not you?
Merineth πŸ‡ΈπŸ‡ͺ
Yes My group partner who left most likely did GPT it
TheRanger
TheRangerβ€’2mo ago
using GPT wont help you become a better programmer
Merineth πŸ‡ΈπŸ‡ͺ
I'm aware. But if i donn't finish this ASAP i'll be dropped from Uni and my life is over. So my priority is just finishing this game
TheRanger
TheRangerβ€’2mo ago
tried to take C# courses online?
Merineth πŸ‡ΈπŸ‡ͺ
Yes but i don't have time
TheRanger
TheRangerβ€’2mo ago
didnt they give u 6 months to make this game?
Merineth πŸ‡ΈπŸ‡ͺ
No It's 6 months overdue I'm already sitting 16 hours a day with other subjects
TheRanger
TheRangerβ€’2mo ago
ah so the deadline was 6 months ago?
Merineth πŸ‡ΈπŸ‡ͺ
Yeah I've already passed the exam, but they wont mark the course as complete until this assignment is done And this assignments difficulty in proportion to the exam are vastly different
TheRanger
TheRangerβ€’2mo ago
odd, must be a super hard uni that wants u to study 16 hours a day every day
Merineth πŸ‡ΈπŸ‡ͺ
And It's supposed to be done in groups of 3+ I mainly just need this finished so i can continue my studies
TheRanger
TheRangerβ€’2mo ago
before the deadline were you working on it?
Merineth πŸ‡ΈπŸ‡ͺ
Yes We divided up the work between us I was meant to handle the windows but they abandoned it and i was left to do everything And i'm not good enough to do it all myself
TheRanger
TheRangerβ€’2mo ago
so what are u going to do with this x and y?
Merineth πŸ‡ΈπŸ‡ͺ
return them i'd assume
TheRanger
TheRangerβ€’2mo ago
correct
Merineth πŸ‡ΈπŸ‡ͺ
private (int x, int y) CellToPixelPosition(int row, int col)
{
int cellWidth = 50;
int cellHeight = 50;

int x = col * cellWidth;
int y = row * cellHeight;

return (x, y);
}
private (int x, int y) CellToPixelPosition(int row, int col)
{
int cellWidth = 50;
int cellHeight = 50;

int x = col * cellWidth;
int y = row * cellHeight;

return (x, y);
}
I think that's correct
TheRanger
TheRangerβ€’2mo ago
yeah now use it in your PlacePiece method it might not be placed correctly but it will give u an idea on how it works
Merineth πŸ‡ΈπŸ‡ͺ
ok
private void PlacePiece(int row, int col, string pieceImage)
{

var (x, y) = CellToPixelPosition(row, col);

Image piece = new Image();
private void PlacePiece(int row, int col, string pieceImage)
{

var (x, y) = CellToPixelPosition(row, col);

Image piece = new Image();
we start like this?
TheRanger
TheRangerβ€’2mo ago
yeah now do u know how to add the Image to the form and set its position?
Merineth πŸ‡ΈπŸ‡ͺ
To the form? As in the grid?
TheRanger
TheRangerβ€’2mo ago
as in the form
Merineth πŸ‡ΈπŸ‡ͺ
No I don't know what a form is
TheRanger
TheRangerβ€’2mo ago
the window
Merineth πŸ‡ΈπŸ‡ͺ
No i don't know how to do that it has something to do with my URL path?
TheRanger
TheRangerβ€’2mo ago
Microsoft has documentations that has a documentation on each of Image's property and methods
Merineth πŸ‡ΈπŸ‡ͺ
What?
TheRanger
TheRangerβ€’2mo ago
this might be tough to read, using a bit of GPT wont hurt in this case it has a property called Source you could use it to point to your image path
Merineth πŸ‡ΈπŸ‡ͺ
this one
TheRanger
TheRangerβ€’2mo ago
yeah
Merineth πŸ‡ΈπŸ‡ͺ
imageSource.UriSource = new Uri("pack://application:,,,/Assignment2;component/Images/black_piece.png"); i tried this but it couldn't find the black_piece.png image
TheRanger
TheRangerβ€’2mo ago
isnt it in your project folder? new Uri("black_piece.png"); should be enough
Merineth πŸ‡ΈπŸ‡ͺ
private void PlacePiece(int row, int col, string pieceImage)
{

var (x, y) = CellToPixelPosition(row, col);

Image piece = new Image();
piece.Source = new Uri("black_piece.png");


}
private void PlacePiece(int row, int col, string pieceImage)
{

var (x, y) = CellToPixelPosition(row, col);

Image piece = new Image();
piece.Source = new Uri("black_piece.png");


}
TheRanger
TheRangerβ€’2mo ago
did it find it?
TheRanger
TheRangerβ€’2mo ago
the document says its UriSource not Source
Merineth πŸ‡ΈπŸ‡ͺ
private void PlacePiece(int row, int col, string pieceImage) { var (x, y) = CellToPixelPosition(row, col); Image piece = new Image(); piece.UriSource = new Uri("black_piece.png"); } is that what you mean?
TheRanger
TheRangerβ€’2mo ago
sure, did it work?
Merineth πŸ‡ΈπŸ‡ͺ
No
No description
TheRanger
TheRangerβ€’2mo ago
ah wops it was the bitmap image, did u try reading the link u posted? it has an example
Merineth πŸ‡ΈπŸ‡ͺ
yes but it doesn't make much sense
TheRanger
TheRangerβ€’2mo ago
what do u mean?
Merineth πŸ‡ΈπŸ‡ͺ
I don't understand it
TheRanger
TheRangerβ€’2mo ago
ur basically creating a new bitmap image, pointing it to its path, then attach it to the Image control
Merineth πŸ‡ΈπŸ‡ͺ
I don't know what a bitmap is and i don't know what image control is
TheRanger
TheRangerβ€’2mo ago
this one might be easier
Image imageControl = new Image
{
Source = new BitmapImage(new Uri("black_piece.png", UriKind.RelativeOrAbsolute)),
Width = 50,
Height = 50
};
Image imageControl = new Image
{
Source = new BitmapImage(new Uri("black_piece.png", UriKind.RelativeOrAbsolute)),
Width = 50,
Height = 50
};
a bitmap is an image like png, jpg the image control is Image piece = new Image(); the image that you will put into your board
Merineth πŸ‡ΈπŸ‡ͺ
uh
private void PlacePiece(int row, int col, string pieceImage)
{

var (x, y) = CellToPixelPosition(row, col);

Image piece = new Image();
Source = new BitmapImage(new Uri("black_piece.png", UriKind.RelativeOrAbsolute));


}
private void PlacePiece(int row, int col, string pieceImage)
{

var (x, y) = CellToPixelPosition(row, col);

Image piece = new Image();
Source = new BitmapImage(new Uri("black_piece.png", UriKind.RelativeOrAbsolute));


}
?
TheRanger
TheRangerβ€’2mo ago
^
Merineth πŸ‡ΈπŸ‡ͺ
oh
private void PlacePiece(int row, int col, string pieceImage)
{

Image imageControl = new Image
{
Source = new BitmapImage(new Uri("black_piece.png", UriKind.RelativeOrAbsolute)),
Width = 50,
Height = 50
};
}
private void PlacePiece(int row, int col, string pieceImage)
{

Image imageControl = new Image
{
Source = new BitmapImage(new Uri("black_piece.png", UriKind.RelativeOrAbsolute)),
Width = 50,
Height = 50
};
}
TheRanger
TheRangerβ€’2mo ago
using Source alone wont work, since you're not telling ur code which Image to apply this source to
Merineth πŸ‡ΈπŸ‡ͺ
It didn't crash but the pieces didn't show up
TheRanger
TheRangerβ€’2mo ago
well yes, you need to add it to your board first BoardGrid.Children.Add(imageControl); might work since BoardGrid is the property of your board according to your code
Merineth πŸ‡ΈπŸ‡ͺ
I tried that earlier but Children doesn't exist
TheRanger
TheRangerβ€’2mo ago
read what i said again
Merineth πŸ‡ΈπŸ‡ͺ
oh I don't have BoardGrid i think?
TheRanger
TheRangerβ€’2mo ago
actually, your friend seems to have already initialized those :bigthonk: which file is this?
Merineth πŸ‡ΈπŸ‡ͺ
GameWindows.xaml.cs
TheRanger
TheRangerβ€’2mo ago
well its defined in the GameGrid.xaml actually i think you should work with that file
Merineth πŸ‡ΈπŸ‡ͺ
ok
TheRanger
TheRangerβ€’2mo ago
from what i see, ur friend already draw the elipses
Merineth πŸ‡ΈπŸ‡ͺ
i did it 99% of everything in the project is me over half a year ago
TheRanger
TheRangerβ€’2mo ago
i assume u used chatgpt?
Merineth πŸ‡ΈπŸ‡ͺ
yes most likely
TheRanger
TheRangerβ€’2mo ago
so technically, u did the elipse, and u dont know how it works?
Merineth πŸ‡ΈπŸ‡ͺ
I remeber dabbling with it because i couldn't get the images to work since that wasn't covered in the course I see i made all of them transparent
TheRanger
TheRangerβ€’2mo ago
i see, what if you made them all black, would it work? in InitializeBoard() in GameGrid.xaml.cs
Merineth πŸ‡ΈπŸ‡ͺ
will try yes
Merineth πŸ‡ΈπŸ‡ͺ
changing the transparant to black it correctly fills in all the pieces on the board
TheRanger
TheRangerβ€’2mo ago
then things got easier from here i wish i checked earlier, lol
Merineth πŸ‡ΈπŸ‡ͺ
so i guess all i have to do is make them transparant again and fill in the 4 correct ones in the middle?
TheRanger
TheRangerβ€’2mo ago
make it transparent again
Merineth πŸ‡ΈπŸ‡ͺ
Yeah i'm terribly sorry Been working so long on this i completely forgot about it
TheRanger
TheRangerβ€’2mo ago
i think ur project is pretty much finished, just needs small things to get added you should initialize your 4 pieces in your InitializeBoard method or wait
Merineth πŸ‡ΈπŸ‡ͺ
private void InitializeBoard()
{
// Clear any existing content (in case of reset)
BoardGrid.Children.Clear();

// Loop through each grid cell and create a tile
for (int row = 0; row < 8; row++)
{
for (int column = 0; column < 8; column++)
{
// Create the tile (Border)
var tile = new Border
{
Background = (row + column) % 2 == 0 ? Brushes.LightGreen : Brushes.DarkGreen, // Alternating green shades
BorderBrush = Brushes.Black,
BorderThickness = new Thickness(1)
};

// Set row and column for the grid placement
Grid.SetRow(tile, row);
Grid.SetColumn(tile, column);

// Add the tile to the board grid
BoardGrid.Children.Add(tile);

// Optionally, add an Ellipse for pieces (will be added later in the UpdateBoard method)
if ((row == 3 && column == 3) || (row == 4 && column == 4)) // White pieces
{
var whitePiece = new Ellipse
{
Fill = Brushes.White, // White piece
Width = 40,
Height = 40,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
tile.Child = whitePiece;
}
else if ((row == 3 && column == 4) || (row == 4 && column == 3)) // Black pieces
{
var blackPiece = new Ellipse
{
Fill = Brushes.Black, // Black piece
Width = 40,
Height = 40,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
tile.Child = blackPiece;
}
}
}
}
private void InitializeBoard()
{
// Clear any existing content (in case of reset)
BoardGrid.Children.Clear();

// Loop through each grid cell and create a tile
for (int row = 0; row < 8; row++)
{
for (int column = 0; column < 8; column++)
{
// Create the tile (Border)
var tile = new Border
{
Background = (row + column) % 2 == 0 ? Brushes.LightGreen : Brushes.DarkGreen, // Alternating green shades
BorderBrush = Brushes.Black,
BorderThickness = new Thickness(1)
};

// Set row and column for the grid placement
Grid.SetRow(tile, row);
Grid.SetColumn(tile, column);

// Add the tile to the board grid
BoardGrid.Children.Add(tile);

// Optionally, add an Ellipse for pieces (will be added later in the UpdateBoard method)
if ((row == 3 && column == 3) || (row == 4 && column == 4)) // White pieces
{
var whitePiece = new Ellipse
{
Fill = Brushes.White, // White piece
Width = 40,
Height = 40,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
tile.Child = whitePiece;
}
else if ((row == 3 && column == 4) || (row == 4 && column == 3)) // Black pieces
{
var blackPiece = new Ellipse
{
Fill = Brushes.Black, // Black piece
Width = 40,
Height = 40,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
tile.Child = blackPiece;
}
}
}
}
TheRanger
TheRangerβ€’2mo ago
public GameGrid()
{
InitializeComponent();
InitializeBoard();
InitializePieces();
UpdateBoard();
}
public GameGrid()
{
InitializeComponent();
InitializeBoard();
InitializePieces();
UpdateBoard();
}
Merineth πŸ‡ΈπŸ‡ͺ
Oh so i should seperate them?
TheRanger
TheRangerβ€’2mo ago
nice but the problem is the problem is that the GameBoard class does not have those pieces added
Merineth πŸ‡ΈπŸ‡ͺ
Hmm Oh i think i see what you mean GameGrid gets them added but GameBoard in GameWindow.xaml does not?
TheRanger
TheRangerβ€’2mo ago
the GameBoard in GameBoard.cs it doesnt seem you initialized this instance of that class anywhere might be useful to initialize it in GameGrid.xaml.cs
Merineth πŸ‡ΈπŸ‡ͺ
Oh initialize a GameBoard Should i keep this?
TheRanger
TheRangerβ€’2mo ago
No you need it to create the board in the window you have 2 boards, one for front end and one for back end the pieces in the back end board should control the pieces in the front end board GameBoard.cs is your back end board GameGrid.xaml is your front end board that is displayed to the user
Merineth πŸ‡ΈπŸ‡ͺ
oh i see so they should be linked basically?
TheRanger
TheRangerβ€’2mo ago
UpdateBoard method pretty much links them
Merineth πŸ‡ΈπŸ‡ͺ
I see
TheRanger
TheRangerβ€’2mo ago
public partial class GameGrid : UserControl
{
GameBoard _board;
public GameGrid()
{
_board = new GameBoard();
InitializeComponent();
InitializeBoard();
}
public partial class GameGrid : UserControl
{
GameBoard _board;
public GameGrid()
{
_board = new GameBoard();
InitializeComponent();
InitializeBoard();
}
add that field, to create the back end game board
Merineth πŸ‡ΈπŸ‡ͺ
oh Ok!
TheRanger
TheRangerβ€’2mo ago
... when you define a variable in a method's scope, it means it only exists there no any other method can access it
Merineth πŸ‡ΈπŸ‡ͺ
Makes sense Ok so we now have an instance of GameBoard called _board
TheRanger
TheRangerβ€’2mo ago
might be better to delete this
// Optionally, add an Ellipse for pieces (will be added later in the UpdateBoard method)
if ((row == 3 && column == 3) || (row == 4 && column == 4)) // White pieces
{
var whitePiece = new Ellipse
{
Fill = Brushes.White, // White piece
Width = 40,
Height = 40,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
tile.Child = whitePiece;
}
else if ((row == 3 && column == 4) || (row == 4 && column == 3)) // Black pieces
{
var blackPiece = new Ellipse
{
Fill = Brushes.Black, // Black piece
Width = 40,
Height = 40,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
tile.Child = blackPiece;
}
// Optionally, add an Ellipse for pieces (will be added later in the UpdateBoard method)
if ((row == 3 && column == 3) || (row == 4 && column == 4)) // White pieces
{
var whitePiece = new Ellipse
{
Fill = Brushes.White, // White piece
Width = 40,
Height = 40,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
tile.Child = whitePiece;
}
else if ((row == 3 && column == 4) || (row == 4 && column == 3)) // Black pieces
{
var blackPiece = new Ellipse
{
Fill = Brushes.Black, // Black piece
Width = 40,
Height = 40,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
tile.Child = blackPiece;
}
cuz u know, when you call the UpdateBoard method, it will do it for you
Merineth πŸ‡ΈπŸ‡ͺ
Oh i see I went back tho
public partial class GameGrid : UserControl
{
GameBoard _board;
public GameGrid()
{
_board = new GameBoard();
InitializeComponent();
InitializeBoard();
}

private void InitializeBoard()
{
// Clear any existing content (in case of reset)
BoardGrid.Children.Clear();

// Loop through each grid cell and create a tile
for (int row = 0; row < 8; row++)
{
for (int column = 0; column < 8; column++)
{
// Create the tile (Border)
var tile = new Border
{
Background = (row + column) % 2 == 0 ? Brushes.LightGreen : Brushes.DarkGreen, // Alternating green shades
BorderBrush = Brushes.Black,
BorderThickness = new Thickness(1)
};

// Optionally, add an Ellipse for pieces (will be added later in the UpdateBoard method)
tile.Child = new Ellipse
{
Fill = Brushes.Transparent, // Pieces will be added later
Width = 40,
Height = 40,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};

// Set row and column for the grid placement
Grid.SetRow(tile, row);
Grid.SetColumn(tile, column);

// Add the tile to the board grid
BoardGrid.Children.Add(tile);
}
}

// Initialize the 4 starting ones with the right color

}
public partial class GameGrid : UserControl
{
GameBoard _board;
public GameGrid()
{
_board = new GameBoard();
InitializeComponent();
InitializeBoard();
}

private void InitializeBoard()
{
// Clear any existing content (in case of reset)
BoardGrid.Children.Clear();

// Loop through each grid cell and create a tile
for (int row = 0; row < 8; row++)
{
for (int column = 0; column < 8; column++)
{
// Create the tile (Border)
var tile = new Border
{
Background = (row + column) % 2 == 0 ? Brushes.LightGreen : Brushes.DarkGreen, // Alternating green shades
BorderBrush = Brushes.Black,
BorderThickness = new Thickness(1)
};

// Optionally, add an Ellipse for pieces (will be added later in the UpdateBoard method)
tile.Child = new Ellipse
{
Fill = Brushes.Transparent, // Pieces will be added later
Width = 40,
Height = 40,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};

// Set row and column for the grid placement
Grid.SetRow(tile, row);
Grid.SetColumn(tile, column);

// Add the tile to the board grid
BoardGrid.Children.Add(tile);
}
}

// Initialize the 4 starting ones with the right color

}
This is what it looks like right now
TheRanger
TheRangerβ€’2mo ago
u can call UpdateBoard() after InitializeBoard();
Merineth πŸ‡ΈπŸ‡ͺ
Right But UpdateBoard() currently expects to arguments
TheRanger
TheRangerβ€’2mo ago
and do u know what argument is it?
Merineth πŸ‡ΈπŸ‡ͺ
Disk[] and Boardstate
TheRanger
TheRangerβ€’2mo ago
so the boardstate, do u know where to find it?
Merineth πŸ‡ΈπŸ‡ͺ
Currently boardstate is only being used in my UpdateBoard method but my assumption is that it's _board?
TheRanger
TheRangerβ€’2mo ago
yes, its stored in _board
Merineth πŸ‡ΈπŸ‡ͺ
Hmm UpdateBoard(_board.BoardState); i think ?
TheRanger
TheRangerβ€’2mo ago
correct, try and see
Merineth πŸ‡ΈπŸ‡ͺ
Holy you are a genius
Merineth πŸ‡ΈπŸ‡ͺ
It did indeed update it correctly
TheRanger
TheRangerβ€’2mo ago
to you maybe im a genius, but to actual seniors, no i dont think you have implemented mouse clicks yet
Merineth πŸ‡ΈπŸ‡ͺ
No sadly not
TheRanger
TheRangerβ€’2mo ago
you should start by implementing a mouseclick event for the GameGrid.xaml
Merineth πŸ‡ΈπŸ‡ͺ
That makes sense, one moment Ok i think i have a basic idea. MouseDown="GameGrid_MouseDown"> I added this to use the function of mouse button in the xaml code Then i added this to my cs file
// Mouse Click event handler
private void GameGrid_MouseDown(object sender, MouseButtonEventArgs e)
{
// Get the position where the user clicked
var mousePosition = e.GetPosition(BoardGrid);
var column = (int)(mousePosition.X / 50); // Assuming each cell is 50px wide
var row = (int)(mousePosition.Y / 50); // Assuming each cell is 50px tall

// Ensure the row and column are within bounds (0-7)
if (row >= 0 && row < 8 && column >= 0 && column < 8)
{
// Check if the move is valid for the current player
Disk currentPlayerDisk = Disk.Black; // Or whichever player is currently playing
if (_board.IsValidMove(row, column, currentPlayerDisk))
{
// Execute the move
_board.ExecuteMove(row, column, currentPlayerDisk);

// Update the board after the move
UpdateBoard(_board.BoardState);
}
else
{
MessageBox.Show("Invalid move! Please try again.");
}
}
}
// Mouse Click event handler
private void GameGrid_MouseDown(object sender, MouseButtonEventArgs e)
{
// Get the position where the user clicked
var mousePosition = e.GetPosition(BoardGrid);
var column = (int)(mousePosition.X / 50); // Assuming each cell is 50px wide
var row = (int)(mousePosition.Y / 50); // Assuming each cell is 50px tall

// Ensure the row and column are within bounds (0-7)
if (row >= 0 && row < 8 && column >= 0 && column < 8)
{
// Check if the move is valid for the current player
Disk currentPlayerDisk = Disk.Black; // Or whichever player is currently playing
if (_board.IsValidMove(row, column, currentPlayerDisk))
{
// Execute the move
_board.ExecuteMove(row, column, currentPlayerDisk);

// Update the board after the move
UpdateBoard(_board.BoardState);
}
else
{
MessageBox.Show("Invalid move! Please try again.");
}
}
}
It does indeed work and i'm able to place them However it's not switching colour I'm still checking why that is the case
TheRanger
TheRangerβ€’2mo ago
something in the GameBoard.cs then
Merineth πŸ‡ΈπŸ‡ͺ
I assume it's because it's not switching player in GameBoard?
TheRanger
TheRangerβ€’2mo ago
debug and find out need a small break, brb
Merineth πŸ‡ΈπŸ‡ͺ
Disk currentPlayerDisk = Disk.Black; // Or whichever player is currently playing It's most likely this part I solved it by adding a method to swap disc colour method
private void TogglePlayerTurn()
{
// Toggle between Black and White
if (_currentPlayerDisk == Disk.Black)
{
_currentPlayerDisk = Disk.White;
}
else
{
_currentPlayerDisk = Disk.Black;
}
}
private void TogglePlayerTurn()
{
// Toggle between Black and White
if (_currentPlayerDisk == Disk.Black)
{
_currentPlayerDisk = Disk.White;
}
else
{
_currentPlayerDisk = Disk.Black;
}
}
TheRanger
TheRangerβ€’2mo ago
cool
Merineth πŸ‡ΈπŸ‡ͺ
and i called this method inside the MouseDown event
private void GameGrid_MouseDown(object sender, MouseButtonEventArgs e)
{
// Get the position where the user clicked
var mousePosition = e.GetPosition(BoardGrid);
var column = (int)(mousePosition.X / 50); // Assuming each cell is 50px wide
var row = (int)(mousePosition.Y / 50); // Assuming each cell is 50px tall

// Ensure the row and column are within bounds (0-7)
if (row >= 0 && row < 8 && column >= 0 && column < 8)
{
// Check if the move is valid for the current player
if (_board.IsValidMove(row, column, _currentPlayerDisk))
{
// Execute the move
_board.ExecuteMove(row, column, _currentPlayerDisk);

// Update the board after the move
UpdateBoard(_board.BoardState);

// Toggle the current player for the next turn
TogglePlayerTurn();
}
else
{
MessageBox.Show("Invalid move! Please try again.");
}
}
}
private void GameGrid_MouseDown(object sender, MouseButtonEventArgs e)
{
// Get the position where the user clicked
var mousePosition = e.GetPosition(BoardGrid);
var column = (int)(mousePosition.X / 50); // Assuming each cell is 50px wide
var row = (int)(mousePosition.Y / 50); // Assuming each cell is 50px tall

// Ensure the row and column are within bounds (0-7)
if (row >= 0 && row < 8 && column >= 0 && column < 8)
{
// Check if the move is valid for the current player
if (_board.IsValidMove(row, column, _currentPlayerDisk))
{
// Execute the move
_board.ExecuteMove(row, column, _currentPlayerDisk);

// Update the board after the move
UpdateBoard(_board.BoardState);

// Toggle the current player for the next turn
TogglePlayerTurn();
}
else
{
MessageBox.Show("Invalid move! Please try again.");
}
}
}
And it does indeed work However it's not flipping the colors of the discs
TheRanger
TheRangerβ€’2mo ago
flip the colors then in the Gameboard.cs
Merineth πŸ‡ΈπŸ‡ͺ
I think it's FlipDiskInDirection method? Yeah i see the problem
Merineth πŸ‡ΈπŸ‡ͺ
It doesn't enter the if or else if it went direction to else and returned void
Merineth πŸ‡ΈπŸ‡ͺ
Aah this is hell to debug. I don't understand. Is it trying to compare and int with White here? No wait itr's comparing Transparent with white
TheRanger
TheRangerβ€’2mo ago
need to watch how reversi works, lol
Merineth πŸ‡ΈπŸ‡ͺ
hahah Yeah that was step 1 for me also, never heard of it until i started this course lol essentially i clicked C4 which should make D4 Black and place a black on C4
TheRanger
TheRangerβ€’2mo ago
so basically when you click, it should find the closest black ellipse that intersects with a white ellipse?
Merineth πŸ‡ΈπŸ‡ͺ
Hmm When i click C4 it should compare all tiles from C4 to E4 and turn them black
TheRanger
TheRangerβ€’2mo ago
looks simple tbh when u click c4 you should find a white piece next to it when you do you determine its direction in this case its right so ull keep iterating to the right, save the positions of the pieces you iterated to into a list, till you hit a black piece once you hit it, flip the pieces that are stored in the list
Merineth πŸ‡ΈπŸ‡ͺ
I think i did it
Merineth πŸ‡ΈπŸ‡ͺ
I just played a full game i think You're a genius the only problem now is that the prompt on who won or not didn't show It's a bit trickier than i thought
Merineth πŸ‡ΈπŸ‡ͺ
i might cry The absolute last thing i need to do is implement the AI part which is the hardest part as it includes threading which i'm absolutely novice at
TheRanger
TheRangerβ€’2mo ago
u could run a method in the background asynchronously
TheRanger
TheRangerβ€’2mo ago
Dot Net Tutorials
Dot Net Tutorials
Task in C#
In this article, I am going to discuss Task in C# with Examples. The Task data type in C# represents an asynchronous operation.
Merineth πŸ‡ΈπŸ‡ͺ
Hmm interesting I was thinking What if i just made it so when it's white turn, and the computer checkmark has been checked, then it will do the moves for it
Merineth πŸ‡ΈπŸ‡ͺ
this one specifically There is one implementation of it already tho
public override async Task<(int x, int y)> RequestMove(GameBoard board, List<(int x, int y)> validMoves)
{
//placeholder move
(int x, int y) selectedMove = (-1, -1);

Random random = new Random();
int index = random.Next(validMoves.Count);

selectedMove = validMoves[index];

//Sleep for 2 seconds
await Task.Delay(2000);

// Return the selected move
return selectedMove;

}
public override async Task<(int x, int y)> RequestMove(GameBoard board, List<(int x, int y)> validMoves)
{
//placeholder move
(int x, int y) selectedMove = (-1, -1);

Random random = new Random();
int index = random.Next(validMoves.Count);

selectedMove = validMoves[index];

//Sleep for 2 seconds
await Task.Delay(2000);

// Return the selected move
return selectedMove;

}
But if i'm being perfectly honest, i'm not sure if it's written correctly Considering it isn't working right now, i'd assume it's not
TheRanger
TheRangerβ€’2mo ago
actually is threading important? the computer can think instantly
Merineth πŸ‡ΈπŸ‡ͺ
Sadly, i think it’s a requirement Will i require an energy drink to keep up with this part? haha so is threading just meant to delay the process of moving by the ai? I'm not sure if you are too familiar with vhdl, but is threading somewhat similar to a process from vhdl?
TheRanger
TheRangerβ€’2mo ago
pretty much it would be great to create a class called AI for maintability and have multiple methods to execute in order
Merineth πŸ‡ΈπŸ‡ͺ
I see Could i potentially rename ComputerPlayer.cs to AI.cs maybe or do you recommend making a completely new file with AI
TheRanger
TheRangerβ€’2mo ago
oh yeah i forgot it exists
Merineth πŸ‡ΈπŸ‡ͺ
πŸ˜” i'm so lost
TheRanger
TheRangerβ€’2mo ago
what are u stuck with?
Merineth πŸ‡ΈπŸ‡ͺ
Well essentially
private void GameGrid_MouseDown(object sender, MouseButtonEventArgs e)
{
// Get the position where the user clicked
var mousePosition = e.GetPosition(BoardGrid);
var column = (int)(mousePosition.X / 50); // Assuming each cell is 50px wide
var row = (int)(mousePosition.Y / 50); // Assuming each cell is 50px tall

// Ensure the row and column are within bounds (0-7)
if (row >= 0 && row < 8 && column >= 0 && column < 8)
{
// Check if the move is valid for the current player
if (_board.IsValidMove(row, column, _currentPlayerDisk))
{
// Execute the move
_board.ExecuteMove(row, column, _currentPlayerDisk);

// Update the board after the move
UpdateBoard(_board.BoardState);

// Toggle the current player for the next turn
TogglePlayerTurn();
}
else
{
MessageBox.Show("Invalid move! Please try again.");
}
}
if (_board.GameOver())
{
InitializeWinnerDialog();
}

}
private void GameGrid_MouseDown(object sender, MouseButtonEventArgs e)
{
// Get the position where the user clicked
var mousePosition = e.GetPosition(BoardGrid);
var column = (int)(mousePosition.X / 50); // Assuming each cell is 50px wide
var row = (int)(mousePosition.Y / 50); // Assuming each cell is 50px tall

// Ensure the row and column are within bounds (0-7)
if (row >= 0 && row < 8 && column >= 0 && column < 8)
{
// Check if the move is valid for the current player
if (_board.IsValidMove(row, column, _currentPlayerDisk))
{
// Execute the move
_board.ExecuteMove(row, column, _currentPlayerDisk);

// Update the board after the move
UpdateBoard(_board.BoardState);

// Toggle the current player for the next turn
TogglePlayerTurn();
}
else
{
MessageBox.Show("Invalid move! Please try again.");
}
}
if (_board.GameOver())
{
InitializeWinnerDialog();
}

}
This part of the code is the one where you select a position on the board which is for the human player to use But if it's a computer player, then i want it to uitilize the ai player instead I guess i can make a new if/else in this code which checks for the player 2s name? if(player2 is a computer) invoke the ComputerPlayer.cs logic else do the human logic (the things below)
TheRanger
TheRangerβ€’2mo ago
yeah the board should have a flag that indicates who's turn is it
Merineth πŸ‡ΈπŸ‡ͺ
Ok i think i did it
if (_isPlayer2Computer && _currentPlayerDisk == Disk.White)
{
await ExecuteAIMove();
return;
}
else
{
// Ensure the row and column are within bounds (0-7)
if (row >= 0 && row < 8 && column >= 0 && column < 8)
{
// Check if the move is valid for the current player
if (_board.IsValidMove(row, column, _currentPlayerDisk))
{
// Execute the move
_board.ExecuteMove(row, column, _currentPlayerDisk);

// Update the board after the move
UpdateBoard(_board.BoardState);

// Toggle the current player for the next turn
TogglePlayerTurn();
}
else
{
MessageBox.Show("Invalid move! Please try again.");
}
}
if (_board.GameOver())
{
InitializeWinnerDialog();
}
}


}
if (_isPlayer2Computer && _currentPlayerDisk == Disk.White)
{
await ExecuteAIMove();
return;
}
else
{
// Ensure the row and column are within bounds (0-7)
if (row >= 0 && row < 8 && column >= 0 && column < 8)
{
// Check if the move is valid for the current player
if (_board.IsValidMove(row, column, _currentPlayerDisk))
{
// Execute the move
_board.ExecuteMove(row, column, _currentPlayerDisk);

// Update the board after the move
UpdateBoard(_board.BoardState);

// Toggle the current player for the next turn
TogglePlayerTurn();
}
else
{
MessageBox.Show("Invalid move! Please try again.");
}
}
if (_board.GameOver())
{
InitializeWinnerDialog();
}
}


}
the await ExectueAIMove(); should now be what the AI should do right?
TheRanger
TheRangerβ€’2mo ago
sure
Merineth πŸ‡ΈπŸ‡ͺ
namespace Assignment2
{
public class ComputerPlayer
{
private Disk _aiDisk;

public ComputerPlayer(Disk aiDisk)
{
_aiDisk = aiDisk;
}

internal async Task<(int x, int y)> ExecuteAIMove(GameBoard board)
{
// Get all valid moves for the AI
List<(int x, int y)> validMoves = board.GetValidMoves(_aiDisk);

// If no valid moves, return (-1, -1) to indicate pass
if (validMoves.Count == 0)
{
return (-1, -1);
}

// Simulate AI thinking time (optional)
await Task.Delay(1000);

// Select a move (Basic AI: Random move)
Random random = new Random();
(int x, int y) selectedMove = validMoves[random.Next(validMoves.Count)];

// Execute the move
board.ExecuteMove(selectedMove.x, selectedMove.y, _aiDisk);

// Return the selected move
return selectedMove;
}
}
}
namespace Assignment2
{
public class ComputerPlayer
{
private Disk _aiDisk;

public ComputerPlayer(Disk aiDisk)
{
_aiDisk = aiDisk;
}

internal async Task<(int x, int y)> ExecuteAIMove(GameBoard board)
{
// Get all valid moves for the AI
List<(int x, int y)> validMoves = board.GetValidMoves(_aiDisk);

// If no valid moves, return (-1, -1) to indicate pass
if (validMoves.Count == 0)
{
return (-1, -1);
}

// Simulate AI thinking time (optional)
await Task.Delay(1000);

// Select a move (Basic AI: Random move)
Random random = new Random();
(int x, int y) selectedMove = validMoves[random.Next(validMoves.Count)];

// Execute the move
board.ExecuteMove(selectedMove.x, selectedMove.y, _aiDisk);

// Return the selected move
return selectedMove;
}
}
}
Ok i think this should work There is one tiny problem i have tho I don't know how to invoke the method Because i assume Task is similar to method?
TheRanger
TheRangerβ€’2mo ago
ur already invoking it here
Merineth πŸ‡ΈπŸ‡ͺ
await ExecuteAIMove(); doesn't work :(
TheRanger
TheRangerβ€’2mo ago
how? what errors do u see
Merineth πŸ‡ΈπŸ‡ͺ
Severity Code Description Project File Line Suppression State Error (active) CS4033 The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'. Assignment2 C:\Users\aljom\Documents\Plugg Programmering filer\OOP\Assignment2\Assignment2Repository\Assignment2\Assignment2\View\GameGrid.xaml.cs 39
TheRanger
TheRangerβ€’2mo ago
there you go its telling you how to fix it
Merineth πŸ‡ΈπŸ‡ͺ
ooooh It already has Task marked afaik? internal async Task<(int x, int y)> ExecuteAIMove(GameBoard board)
TheRanger
TheRangerβ€’2mo ago
its talking about the method that is calling it the GameGrid_MouseDown one
Merineth πŸ‡ΈπŸ‡ͺ
Oh i see It's expecting the MouseDown method to be a Task?
TheRanger
TheRangerβ€’2mo ago
yeah
Merineth πŸ‡ΈπŸ‡ͺ
Ahh i see that seems to fix it Is that a requirement when it comes to threading and asynchronous tasks? Severity Code Description Project File Line Suppression State Error (active) CS0103 The name 'ExecuteAIMove' does not exist in the current context Assignment2 C:\Users\aljom\Documents\Plugg Programmering filer\OOP\Assignment2\Assignment2Repository\Assignment2\Assignment2\View\GameGrid.xaml.cs 39 I'm assuming this is becuase ExecuteAIMove is called in GameGrid.xaml.cs but is defined in CamputerPlayer.cs?
TheRanger
TheRangerβ€’2mo ago
if its defined there then yes
Merineth πŸ‡ΈπŸ‡ͺ
Like no matter what i do i keep getting errors it's so frustrating if (isPlayer2Computer) { player2 = new ComputerPlayer(player2Name, Disk.Black); } Severity Code Description Project File Line Suppression State Error (active) CS1729 'ComputerPlayer' does not contain a constructor that takes 2 arguments Assignment2 C:\Users\aljom\Documents\Plugg Programmering filer\OOP\Assignment2\Assignment2Repository\Assignment2\Assignment2\View\GameWindow.xaml.cs 73
public ComputerPlayer(Disk aiDisk) { _aiDisk = aiDisk; }
TheRanger
TheRangerβ€’2mo ago
it tells you why
Merineth πŸ‡ΈπŸ‡ͺ
public class ComputerPlayer
{
private Disk _aiDisk;
private string _aiName;

public ComputerPlayer(string player2Name, Disk aiDisk)
{
_aiDisk = aiDisk;
this._aiName = player2Name;
}
public class ComputerPlayer
{
private Disk _aiDisk;
private string _aiName;

public ComputerPlayer(string player2Name, Disk aiDisk)
{
_aiDisk = aiDisk;
this._aiName = player2Name;
}
Yeah iu updated it with it and then it complains again Severity Code Description Project File Line Suppression State Error (active) CS0029 Cannot implicitly convert type 'Assignment2.Model.Assignment2.ComputerPlayer' to 'Assignment2.Model.Player' Assignment2 C:\Users\aljom\Documents\Plugg Programmering filer\OOP\Assignment2\Assignment2Repository\Assignment2\Assignment2\View\GameWindow.xaml.cs 73 I have a hard time understand why it even is complaining about that when player2Name is a string
TheRanger
TheRangerβ€’2mo ago
can u show that line
Merineth πŸ‡ΈπŸ‡ͺ
private void NewGameButton_Click(object sender, RoutedEventArgs e)
{
// Show the SetUpGameDialog to collect player names and types
SetUpGameDialog setUpDialog = new SetUpGameDialog();
bool? result = setUpDialog.ShowDialog(); // Show dialog and wait for result

if (result == true) // If OK was clicked (DialogResult = true)
{
// Retrieve player names and player types
string player1Name = setUpDialog.Player1Name;
string player2Name = setUpDialog.Player2Name;
bool isPlayer2Computer = setUpDialog.IsPlayer2Computer;


/* Creates 3 instances for the if statement. player 1 is always human
so i always creater player1 as HumanPlayer and the if determines if it's computer or human.*/
Player player1 = new HumanPlayer(player1Name, Disk.White);
Player player2;
if (isPlayer2Computer)
{
player2 = new ComputerPlayer(player2Name, Disk.Black);
}
else
{
player2 = new HumanPlayer(player2Name, Disk.Black);
}


// Create the GameManager instance.
GameManager game = new GameManager(player1Name, player2Name);
game.StartGame(GameGridControl);

}
else
{
// If the user cancels the setup
MessageBox.Show("Game setup was canceled.", "Canceled");
}
}
private void NewGameButton_Click(object sender, RoutedEventArgs e)
{
// Show the SetUpGameDialog to collect player names and types
SetUpGameDialog setUpDialog = new SetUpGameDialog();
bool? result = setUpDialog.ShowDialog(); // Show dialog and wait for result

if (result == true) // If OK was clicked (DialogResult = true)
{
// Retrieve player names and player types
string player1Name = setUpDialog.Player1Name;
string player2Name = setUpDialog.Player2Name;
bool isPlayer2Computer = setUpDialog.IsPlayer2Computer;


/* Creates 3 instances for the if statement. player 1 is always human
so i always creater player1 as HumanPlayer and the if determines if it's computer or human.*/
Player player1 = new HumanPlayer(player1Name, Disk.White);
Player player2;
if (isPlayer2Computer)
{
player2 = new ComputerPlayer(player2Name, Disk.Black);
}
else
{
player2 = new HumanPlayer(player2Name, Disk.Black);
}


// Create the GameManager instance.
GameManager game = new GameManager(player1Name, player2Name);
game.StartGame(GameGridControl);

}
else
{
// If the user cancels the setup
MessageBox.Show("Game setup was canceled.", "Canceled");
}
}
Merineth πŸ‡ΈπŸ‡ͺ
Does it have something to do with player2 being Player type? Ok i think i solved it
Player player1 = new HumanPlayer(player1Name, Disk.White);
if (isPlayer2Computer)
{
ComputerPlayer player2;
player2 = new ComputerPlayer(player2Name, Disk.Black);
}
else
{
Player player2;
player2 = new HumanPlayer(player2Name, Disk.Black);
}
Player player1 = new HumanPlayer(player1Name, Disk.White);
if (isPlayer2Computer)
{
ComputerPlayer player2;
player2 = new ComputerPlayer(player2Name, Disk.Black);
}
else
{
Player player2;
player2 = new HumanPlayer(player2Name, Disk.Black);
}
100% pure intuition
TheRanger
TheRangerβ€’2mo ago
ill let you think this one ^^
Merineth πŸ‡ΈπŸ‡ͺ
Hmm ok i managed to solve all the errors and it compiles but i have one small question
private async void GameGrid_MouseDown(object sender, MouseButtonEventArgs e)
{
var mousePosition = e.GetPosition(BoardGrid);
int column = (int)(mousePosition.X / 50);
int row = (int)(mousePosition.Y / 50);

if (row >= 0 && row < 8 && column >= 0 && column < 8)
{
if (_board.IsValidMove(row, column, _currentPlayerDisk))
{
_board.ExecuteMove(row, column, _currentPlayerDisk);
UpdateBoard(_board.BoardState);
TogglePlayerTurn();

// If Player 2 is a computer, execute AI move
if (_isPlayer2Computer)
{
await Task.Delay(1000); // Optional delay for realism
var aiMove = await _computerPlayer.ExecuteAIMove(_board);
_board.ExecuteMove(aiMove.x, aiMove.y, _currentPlayerDisk);
UpdateBoard(_board.BoardState);
TogglePlayerTurn();
}
}
else
{
MessageBox.Show("Invalid move! Please try again.");
}
}
private async void GameGrid_MouseDown(object sender, MouseButtonEventArgs e)
{
var mousePosition = e.GetPosition(BoardGrid);
int column = (int)(mousePosition.X / 50);
int row = (int)(mousePosition.Y / 50);

if (row >= 0 && row < 8 && column >= 0 && column < 8)
{
if (_board.IsValidMove(row, column, _currentPlayerDisk))
{
_board.ExecuteMove(row, column, _currentPlayerDisk);
UpdateBoard(_board.BoardState);
TogglePlayerTurn();

// If Player 2 is a computer, execute AI move
if (_isPlayer2Computer)
{
await Task.Delay(1000); // Optional delay for realism
var aiMove = await _computerPlayer.ExecuteAIMove(_board);
_board.ExecuteMove(aiMove.x, aiMove.y, _currentPlayerDisk);
UpdateBoard(_board.BoardState);
TogglePlayerTurn();
}
}
else
{
MessageBox.Show("Invalid move! Please try again.");
}
}
This part here: I just realized that unless a button is pressed it will never trigger the AI part
// If Player 2 is a computer, execute AI move
if (_isPlayer2Computer)
{
await Task.Delay(1000); // Optional delay for realism
var aiMove = await _computerPlayer.ExecuteAIMove(_board);
_board.ExecuteMove(aiMove.x, aiMove.y, _currentPlayerDisk);
UpdateBoard(_board.BoardState);
TogglePlayerTurn();
}
// If Player 2 is a computer, execute AI move
if (_isPlayer2Computer)
{
await Task.Delay(1000); // Optional delay for realism
var aiMove = await _computerPlayer.ExecuteAIMove(_board);
_board.ExecuteMove(aiMove.x, aiMove.y, _currentPlayerDisk);
UpdateBoard(_board.BoardState);
TogglePlayerTurn();
}
this part specifically Is it possible to make it so after the human has done one turn, it will then perform that if statement?
TheRanger
TheRangerβ€’2mo ago
yeah
Merineth πŸ‡ΈπŸ‡ͺ
Honestly the main problem i'm facing is
private async void GameGrid_MouseDown(object sender, MouseButtonEventArgs e)
{
var mousePosition = e.GetPosition(BoardGrid);
int column = (int)(mousePosition.X / 50);
int row = (int)(mousePosition.Y / 50);

if (row >= 0 && row < 8 && column >= 0 && column < 8)
{
if (_board.IsValidMove(row, column, _currentPlayerDisk))
{
_board.ExecuteMove(row, column, _currentPlayerDisk);
UpdateBoard(_board.BoardState);
TogglePlayerTurn();

// If Player 2 is a computer, execute AI move
if (_isPlayer2Computer)
{
await Task.Delay(1000); // Optional delay for realism
var aiMove = await _computerPlayer.ExecuteAIMove(_board);
_board.ExecuteMove(aiMove.x, aiMove.y, _currentPlayerDisk);
UpdateBoard(_board.BoardState);
TogglePlayerTurn();
}
}
else
{
MessageBox.Show("Invalid move! Please try again.");
}
}
private async void GameGrid_MouseDown(object sender, MouseButtonEventArgs e)
{
var mousePosition = e.GetPosition(BoardGrid);
int column = (int)(mousePosition.X / 50);
int row = (int)(mousePosition.Y / 50);

if (row >= 0 && row < 8 && column >= 0 && column < 8)
{
if (_board.IsValidMove(row, column, _currentPlayerDisk))
{
_board.ExecuteMove(row, column, _currentPlayerDisk);
UpdateBoard(_board.BoardState);
TogglePlayerTurn();

// If Player 2 is a computer, execute AI move
if (_isPlayer2Computer)
{
await Task.Delay(1000); // Optional delay for realism
var aiMove = await _computerPlayer.ExecuteAIMove(_board);
_board.ExecuteMove(aiMove.x, aiMove.y, _currentPlayerDisk);
UpdateBoard(_board.BoardState);
TogglePlayerTurn();
}
}
else
{
MessageBox.Show("Invalid move! Please try again.");
}
}
_isPlayer2Computer evaltues to false even tho it should be true
TheRanger
TheRangerβ€’2mo ago
what makes u think so? did you set it to true from anywhere?
Merineth πŸ‡ΈπŸ‡ͺ
Ah ur right it isn't evaluated anywhere :sadge:
leowest
leowestβ€’2mo ago
just one thing, for ui events they dont need to be a Task should be async void in fact I believe u can't even make them a task in WPF as there is no signature for it but there is for async void
Merineth πŸ‡ΈπŸ‡ͺ
I might lose my mind? I added this
if (IsPlayer2Computer)
{
gameGrid._isPlayer2Computer = true;
}
if (IsPlayer2Computer)
{
gameGrid._isPlayer2Computer = true;
}
to my SetupGameDialog.xaml.cs So it indeed gets set to true but it STILL evaluates to false
Merineth πŸ‡ΈπŸ‡ͺ
here it gets evalueted to true
TheRanger
TheRangerβ€’2mo ago
u mustve set it to false at some point what does TogglePlayerTurn() method do?
Merineth πŸ‡ΈπŸ‡ͺ
private void TogglePlayerTurn() { // Toggle between Black and White if (_currentPlayerDisk == Disk.Black) { _currentPlayerDisk = Disk.White; } else { _currentPlayerDisk = Disk.Black; } } it just swaps the colour I've carefully gone through it 3 times now and i can't see when _isPlayer2Computer be turned to false Is it possible to set a breakpoint so it checks for any change in a variable/boolean? Ok there seems to be a "Watch" debug mode
TheRanger
TheRangerβ€’2mo ago
yea if its a property you could put a breakpoint to its setter
Merineth πŸ‡ΈπŸ‡ͺ
Ok i found out that it changes to false when MouseDown is triggered but i have literally zero idea why
TheRanger
TheRangerβ€’2mo ago
i would advise you not to put some game logic to the front end code toggleplayerturn() and _currentPlayerDisk for example should be in the GameBoard class
Merineth πŸ‡ΈπŸ‡ͺ
yes i know this code is a nightmare i just want to make it work been like an hour on this problem alone now
TheRanger
TheRangerβ€’2mo ago
it will actually be more nightmare the further you go so i advise you move them to that class,
Merineth πŸ‡ΈπŸ‡ͺ
What am i supposed to move
private async void GameGrid_MouseDown(object sender, MouseButtonEventArgs e)
{
var mousePosition = e.GetPosition(BoardGrid);
int column = (int)(mousePosition.X / 50);
int row = (int)(mousePosition.Y / 50);

if (row >= 0 && row < 8 && column >= 0 && column < 8)
{
if (_board.IsValidMove(row, column, _currentPlayerDisk))
{
_board.ExecuteMove(row, column, _currentPlayerDisk);
UpdateBoard(_board.BoardState);
TogglePlayerTurn();

// If Player 2 is a computer, execute AI move
if (_isPlayer2Computer)
{
await Task.Delay(1000); // Optional delay for realism
var aiMove = await _computerPlayer.ExecuteAIMove(_board);
_board.ExecuteMove(aiMove.x, aiMove.y, _currentPlayerDisk);
UpdateBoard(_board.BoardState);
TogglePlayerTurn();
}
}
else
{
MessageBox.Show("Invalid move! Please try again.");
}
}

if (_board.GameOver())
{
InitializeWinnerDialog();
}
}
private async void GameGrid_MouseDown(object sender, MouseButtonEventArgs e)
{
var mousePosition = e.GetPosition(BoardGrid);
int column = (int)(mousePosition.X / 50);
int row = (int)(mousePosition.Y / 50);

if (row >= 0 && row < 8 && column >= 0 && column < 8)
{
if (_board.IsValidMove(row, column, _currentPlayerDisk))
{
_board.ExecuteMove(row, column, _currentPlayerDisk);
UpdateBoard(_board.BoardState);
TogglePlayerTurn();

// If Player 2 is a computer, execute AI move
if (_isPlayer2Computer)
{
await Task.Delay(1000); // Optional delay for realism
var aiMove = await _computerPlayer.ExecuteAIMove(_board);
_board.ExecuteMove(aiMove.x, aiMove.y, _currentPlayerDisk);
UpdateBoard(_board.BoardState);
TogglePlayerTurn();
}
}
else
{
MessageBox.Show("Invalid move! Please try again.");
}
}

if (_board.GameOver())
{
InitializeWinnerDialog();
}
}
thius currently doersn't work because the if statemnt is not working properly i checked the box that it is an ai and it still returns as false
TheRanger
TheRangerβ€’2mo ago
have u figured out what sets it to false?
Merineth πŸ‡ΈπŸ‡ͺ
Yes GameGrid_MouseDown
TheRanger
TheRangerβ€’2mo ago
where exactly in that method?
Merineth πŸ‡ΈπŸ‡ͺ
Whenever the button is clicked it changes to false i put a breakpoint on the method itself
TheRanger
TheRangerβ€’2mo ago
which line in the method?
Merineth πŸ‡ΈπŸ‡ͺ
Let me quadruple check, one moment
TheRanger
TheRangerβ€’2mo ago
also _isPlayer2Computer is pointless you dont need it cuz you can just check if the player2 variable is an instance of ComputerPlayer
Player player2;

if (player2 is ComputerPlayer)
{
//your code
}
Player player2;

if (player2 is ComputerPlayer)
{
//your code
}
by using the is operator, you can check if the variable can be downcasted to that class
Animal animal = new Tiger();

if (animal is Tiger tiger)
{
tiger.RunAMethod();
}
Animal animal = new Tiger();

if (animal is Tiger tiger)
{
tiger.RunAMethod();
}
your ComputerPlayer class extends Player, so it will definitely work
Merineth πŸ‡ΈπŸ‡ͺ
But player2 is defined in Setupgamedialog and i'm having the if in gamegrid God i despise c#
TheRanger
TheRangerβ€’2mo ago
Player2 should be defined in the back end classes
TheRanger
TheRangerβ€’2mo ago
it means its not defined
Merineth πŸ‡ΈπŸ‡ͺ
That's why i was trying to pass _isplayercomputer
TheRanger
TheRangerβ€’2mo ago
where is player1 defined?
Merineth πŸ‡ΈπŸ‡ͺ
GameManager So is player2
TheRanger
TheRangerβ€’2mo ago
thats just a string, im talking about an instance of class HumanPlayer and ComputerPlayer if you never use them why create them in the first place?
Merineth πŸ‡ΈπŸ‡ͺ
I don't know i have so much code i have literally no idea what i'm doing
TheRanger
TheRangerβ€’2mo ago
thats what happens when you rely too much on chatgpt
Merineth πŸ‡ΈπŸ‡ͺ
It was either that or death
leowest
leowestβ€’2mo ago
I mean u literally reached death by not knowing what your code does
Merineth πŸ‡ΈπŸ‡ͺ
what?
leowest
leowestβ€’2mo ago
relying too much on chatgpt to do the code etc
Merineth πŸ‡ΈπŸ‡ͺ
relying i didn't know how to do it in the firs tplace
leowest
leowestβ€’2mo ago
what u need is something to have the state of your game
TheRanger
TheRangerβ€’2mo ago
they have GameManager defined atleast, just needs to do some modifications https://github.com/aljomatrix/Assignment2Repository
GitHub
GitHub - aljomatrix/Assignment2Repository
Contribute to aljomatrix/Assignment2Repository development by creating an account on GitHub.
leowest
leowestβ€’2mo ago
and that is where chatgpt is the worst because u dont know how to do X and rely on something to tell u what to do which doesnt know either because it doesnt have a broad concept of what u are doing that is why we dont suggest people to use chatgpt at all for learning I didnt see the repo yet I was just following bits of the conversation but yeah u would use something like the GameManager to handle the state of your game so you can access player 1, 2 etc
Merineth πŸ‡ΈπŸ‡ͺ
I can totally understand that people who know how to code see chatgpt as something to avoid. But when you are a student like me where you are made to do a group project completely solo where the difficulty on the project vs the exam is so huge you have literally no idea how to even begin the project, much less finish it in a very limited time on top of having other subjects to study for and assignments to turn in. Chatgpt becomes the only option in order to prevent expulsion The choice between expulsion and chatgpt, isn't much of a choice at all
leowest
leowestβ€’2mo ago
I mean if you are made to make it solo the first thing u should be doing is raising that to your teacher and negotiate with him a smaller task. Secondly it doesnt change the fact you should learn by actually doing research on the tools you need to use instead of relying on chat gpt more over u have this great communicate that can help u understand what X or Y does if u dont understand it your self
Merineth πŸ‡ΈπŸ‡ͺ
Either way, i have no idea how to implement the if statement. It's been two hours and i can't find the reason why _iscomputerplayer turning false
leowest
leowestβ€’2mo ago
im not here trying to bash you for using gpt but your comment there was literally what happened.
Merineth πŸ‡ΈπŸ‡ͺ
If i had the luxury of being able to do my own research and learn properly about coding, then i wouldn't sit here and be berated for using chatgpt and begging for help in order to finish this assignment
leowest
leowestβ€’2mo ago
Anyway give me a few to look at your project and see what is usable vs what is not
Merineth πŸ‡ΈπŸ‡ͺ
Thanks
TheRanger
TheRangerβ€’2mo ago
you could start by initializing HumanPlayer and ComputerPlayer instances in your GameManager class
leowest
leowestβ€’2mo ago
few questions, are you suppose to use mvvm at all?
Merineth πŸ‡ΈπŸ‡ͺ
Yes, it's supposedly a requirement
leowest
leowestβ€’2mo ago
ok is there any mention on whether u can use external libraries or u have to write everything vanilla?
Merineth πŸ‡ΈπŸ‡ͺ
I'd assume vanilla Quite frankly i don't even think they go through the code when grading
TheRanger
TheRangerβ€’2mo ago
in my days they opened my code and asked me what this code and that code does πŸ˜„
leowest
leowestβ€’2mo ago
yeah im asking because you're hardly using mvvm apparently and if u have to write it vannilla is a bit more of a pain same is the repo currently buildable?
Merineth πŸ‡ΈπŸ‡ͺ
Idk what buildable means As in, compileable?
leowest
leowestβ€’2mo ago
when u right click and click build sure compileable
Merineth πŸ‡ΈπŸ‡ͺ
No
leowest
leowestβ€’2mo ago
also do u have any other reqs like use Dependency Injection etc?
Merineth πŸ‡ΈπŸ‡ͺ
The requirements are like 14 pages long
leowest
leowestβ€’2mo ago
I suppose u dont have a screenshot of it we can look at nvm u do
TheRanger
TheRangerβ€’2mo ago
oh man i wish you told me about that pdf
leowest
leowestβ€’2mo ago
ok so mvvm is optional that's helpful to cut the chase specially since most of your code is in the code behind already
TheRanger
TheRangerβ€’2mo ago
it even gives you hints on how to implement stuff
leowest
leowestβ€’2mo ago
yeh its very detailed
Merineth πŸ‡ΈπŸ‡ͺ
Well i'm almost done just need the goddamn if statement tot work so my ai works
TheRanger
TheRangerβ€’2mo ago
without finishing the GameManager class?
Merineth πŸ‡ΈπŸ‡ͺ
i think so Like i noticed just now going into the assignment page and seeing they have apparantly moved the deadline to Aug 17 Nvm My goal here is to make it so it works submit it and get feedback if they aren't happy about something
TheRanger
TheRangerβ€’2mo ago
trust me i think its faster to finish if we finish making the GameManager class
leowest
leowestβ€’2mo ago
same so listen I see the problem you have created the players locally in your GameWindow
Merineth πŸ‡ΈπŸ‡ͺ
I trust you. But i think you severely underestimate overestimate the knowledge i have about C# and what i've learnt from class
leowest
leowestβ€’2mo ago
what u would do instead if make use of the GameManager and have the players set there and then do the same on GameGrid and use the GamaManager player's object
TheRanger
TheRangerβ€’2mo ago
no worries you will learn while we're helping you
leowest
leowestβ€’2mo ago
that is looking at your code and taking the simplest route not even the correct route if u want to make this MVVM then u would have to change A LOT of things not even kidding
Merineth πŸ‡ΈπŸ‡ͺ
Yeah i know i gave up halfway of keeping it MVVM
leowest
leowestβ€’2mo ago
MVVM can be great but its not simple to understand what problem it solves and how to use it and separate its concerns a lot of people fail at that even I sometimes need to ask for help with certain things
Merineth πŸ‡ΈπŸ‡ͺ
So you want me ot implement this?
No description
leowest
leowestβ€’2mo ago
No description
leowest
leowestβ€’2mo ago
you're setting up the player here, the main problem is you're assigning everything locally so once it goes out of that method everything there is pretty much lost
Merineth πŸ‡ΈπŸ‡ͺ
Becuase it's inside the if? or rather when the new game button dissapears/closese?
leowest
leowestβ€’2mo ago
you understand what a local variable is?
Merineth πŸ‡ΈπŸ‡ͺ
Yes
leowest
leowestβ€’2mo ago
then explain to me
Merineth πŸ‡ΈπŸ‡ͺ
It's declared in NewGameButton so it's restricted to it?
leowest
leowestβ€’2mo ago
a local variable only exists in that block, for example:
void Start()
{
Player player = new Player();
}

void Stop()
{
Console.WriteLine(player.Name);
}
void Start()
{
Player player = new Player();
}

void Stop()
{
Console.WriteLine(player.Name);
}
player only exists within the method Start.
Merineth πŸ‡ΈπŸ‡ͺ
Yes i know that
leowest
leowestβ€’2mo ago
so you cannot access it on Stop so none of the code in the image I posted above is usable anywhere else
Merineth πŸ‡ΈπŸ‡ͺ
So what is the solution? No matter where i make it, it'll be restricted to where i make it
leowest
leowestβ€’2mo ago
you would have a property or field to hold the GameManager and update it there
Merineth πŸ‡ΈπŸ‡ͺ
I see. So create it in GameWindow but hold it in game manager?
TheRanger
TheRangerβ€’2mo ago
hint: GameManager.Instance might be very useful
leowest
leowestβ€’2mo ago
now the other problem im looking at is how the wpf is laid give me a moment you even have it declared as a field but u never used it but yes beyond that u could make it a singleton but then again it might be another concept u dont know yet
leowest
leowestβ€’2mo ago
at the very top
No description
leowest
leowestβ€’2mo ago
but for some reason u decided to create a new local instance of the GameManager
Merineth πŸ‡ΈπŸ‡ͺ
class GameManager
{
public Player player1 { set; get; }
public Player player2 { set; get; }
public ComputerPlayer Player2 { set; get; }
class GameManager
{
public Player player1 { set; get; }
public Player player2 { set; get; }
public ComputerPlayer Player2 { set; get; }
So i could do something like this. And set them from my GameWindow?
leowest
leowestβ€’2mo ago
yes you could not sure why u would have 3 Players thou it would make more sense to have a property in Player to tell whether its a computer or a human or if u must have a Computer and a Player class just have those 2
TheRanger
TheRangerβ€’2mo ago
πŸ‘€ i never saw set being placed before get, i guess it works lol
leowest
leowestβ€’2mo ago
same hehe
TheRanger
TheRangerβ€’2mo ago
i dont think they know polymorphism
Merineth πŸ‡ΈπŸ‡ͺ
So this here would be my GameWindow
Player player1 = new HumanPlayer(player1Name, Disk.White);
gameManager.player1 = player1;
if (isPlayer2Computer)
{
ComputerPlayer player2;
player2 = new ComputerPlayer(player2Name, Disk.Black);
gameManager.AIPlayer2 = player2; ;
}
else
{
Player player2;
player2 = new HumanPlayer(player2Name, Disk.Black);
gameManager.player2 = player2;
}
Player player1 = new HumanPlayer(player1Name, Disk.White);
gameManager.player1 = player1;
if (isPlayer2Computer)
{
ComputerPlayer player2;
player2 = new ComputerPlayer(player2Name, Disk.Black);
gameManager.AIPlayer2 = player2; ;
}
else
{
Player player2;
player2 = new HumanPlayer(player2Name, Disk.Black);
gameManager.player2 = player2;
}
And this here would be my GameManager
class GameManager
{
public Player player1 { set; get; }
public Player player2 { set; get; }
public ComputerPlayer AIPlayer2 { set; get; }

public GameManager(string player1, string player2)
{
this.player1 = player1;
this.player2 = player2;
}

public void StartGame(GameGrid gameGridControl)
{

}

}
class GameManager
{
public Player player1 { set; get; }
public Player player2 { set; get; }
public ComputerPlayer AIPlayer2 { set; get; }

public GameManager(string player1, string player2)
{
this.player1 = player1;
this.player2 = player2;
}

public void StartGame(GameGrid gameGridControl)
{

}

}
And this would make it so it doesn't disappear?
TheRanger
TheRangerβ€’2mo ago
delete the AIPlayer2 line
Merineth πŸ‡ΈπŸ‡ͺ
Isn't it that one type can be many types?
TheRanger
TheRangerβ€’2mo ago
you can basically assign an instance of ComputerPlayer to player2 since it extends Player class
Merineth πŸ‡ΈπŸ‡ͺ
Says i can't do that
TheRanger
TheRangerβ€’2mo ago
oh it doesnt extend the Player class, your pdf does say it should extend it
Merineth πŸ‡ΈπŸ‡ͺ
I don't know what extend means
TheRanger
TheRangerβ€’2mo ago
derive, ComputerPlayer should be a subclass of Player
Merineth πŸ‡ΈπŸ‡ͺ
Ah Yeah it should've been seems that wasn't done If i try to add that i get 100x errors
Merineth πŸ‡ΈπŸ‡ͺ
every change i make i get 100x more errors i tried making it internal but dthat wasn't allowed either
TheRanger
TheRangerβ€’2mo ago
yeah its asking you to override the abstract method defined in the super class those are just 6 errors not 100
leowest
leowestβ€’2mo ago
funny he did HumanPlayer right but didnt for Computer
Merineth πŸ‡ΈπŸ‡ͺ
So the problem is that i'm not implementing the request move method from player?
TheRanger
TheRangerβ€’2mo ago
yeah
Merineth πŸ‡ΈπŸ‡ͺ
Don't i just add override to it?
TheRanger
TheRangerβ€’2mo ago
yes, its an abstract method so u are forced to override it
leowest
leowestβ€’2mo ago
you might also need to make the classes public so that the GameManager can be passed down to the DataContext and be visible to your gamegrid
Merineth πŸ‡ΈπŸ‡ͺ
public override async Task<(int x, int y)> RequestMove(GameBoard board, List<(int x, int y)> validMoves)
{
await Task.Delay(1); // Simulates async behavior
return validMoves.Count > 0 ? validMoves[0] : (0, 0); // Returns the first valid move or (0,0) as fallback
}
public override async Task<(int x, int y)> RequestMove(GameBoard board, List<(int x, int y)> validMoves)
{
await Task.Delay(1); // Simulates async behavior
return validMoves.Count > 0 ? validMoves[0] : (0, 0); // Returns the first valid move or (0,0) as fallback
}
Like so i guess the same as HumanPlayer
leowest
leowestβ€’2mo ago
I mean is it suppose to be the same? didnt u have logic for the ai
Merineth πŸ‡ΈπŸ‡ͺ
I dont know i made it in gamegrid
private async void GameGrid_MouseDown(object sender, MouseButtonEventArgs e)
{
var mousePosition = e.GetPosition(BoardGrid);
int column = (int)(mousePosition.X / 50);
int row = (int)(mousePosition.Y / 50);

if (row >= 0 && row < 8 && column >= 0 && column < 8)
{
if (_board.IsValidMove(row, column, _currentPlayerDisk))
{
_board.ExecuteMove(row, column, _currentPlayerDisk);
UpdateBoard(_board.BoardState);
TogglePlayerTurn();

// If Player 2 is a computer, execute AI move
if (player2 is ComputerPlayer)
{
await Task.Delay(1000); // Optional delay for realism
var aiMove = await _computerPlayer.ExecuteAIMove(_board);
_board.ExecuteMove(aiMove.x, aiMove.y, _currentPlayerDisk);
UpdateBoard(_board.BoardState);
TogglePlayerTurn();
}
}
else
{
MessageBox.Show("Invalid move! Please try again.");
}
}
private async void GameGrid_MouseDown(object sender, MouseButtonEventArgs e)
{
var mousePosition = e.GetPosition(BoardGrid);
int column = (int)(mousePosition.X / 50);
int row = (int)(mousePosition.Y / 50);

if (row >= 0 && row < 8 && column >= 0 && column < 8)
{
if (_board.IsValidMove(row, column, _currentPlayerDisk))
{
_board.ExecuteMove(row, column, _currentPlayerDisk);
UpdateBoard(_board.BoardState);
TogglePlayerTurn();

// If Player 2 is a computer, execute AI move
if (player2 is ComputerPlayer)
{
await Task.Delay(1000); // Optional delay for realism
var aiMove = await _computerPlayer.ExecuteAIMove(_board);
_board.ExecuteMove(aiMove.x, aiMove.y, _currentPlayerDisk);
UpdateBoard(_board.BoardState);
TogglePlayerTurn();
}
}
else
{
MessageBox.Show("Invalid move! Please try again.");
}
}
the AI part is the if statement which i was trying to get to work 19:00 or so
TheRanger
TheRangerβ€’2mo ago
i would move that code to a method in the GameManager class and all what GameGrid_MouseDown would do is to tell the GameManager that it clicked on that position
Merineth πŸ‡ΈπŸ‡ͺ
I tried doing that but now i have 21 errors
TheRanger
TheRangerβ€’2mo ago
no worries thats normal, it can get fixed quick
Merineth πŸ‡ΈπŸ‡ͺ
gameManager doesn't exist in gamegrid
TheRanger
TheRangerβ€’2mo ago
you should know what to do, move those methods to the GameManager class
leowest
leowestβ€’2mo ago
as your code is right now there is only 1 way to access GamaManager from GameGrid which would be to get the parent window and access the parent window property GameManager if u made it a public property that is why they suggest you use mvvm in the pdf and defining a global resource for the GameWindowViewModel at hints 8 because that way, GameGrid would easily see the ViewModel which would contain the GameManager
Merineth πŸ‡ΈπŸ‡ͺ
wait what
leowest
leowestβ€’2mo ago
any window within your main window would see it
Merineth πŸ‡ΈπŸ‡ͺ
so i should move MouseDown to GameManager?
leowest
leowestβ€’2mo ago
no that is not what I said
Merineth πŸ‡ΈπŸ‡ͺ
I was referring to R
TheRanger
TheRangerβ€’2mo ago
i meant the methods like TogglePlayerTurn as for _board you would need to create its field in the GameManager class
Merineth πŸ‡ΈπŸ‡ͺ
I don't think i can move them to gamemanager
TheRanger
TheRangerβ€’2mo ago
trust me bro
Merineth πŸ‡ΈπŸ‡ͺ
i'm about to pass out i'm going to take a break
TheRanger
TheRangerβ€’2mo ago
i have to go very soon anyway
Merineth πŸ‡ΈπŸ‡ͺ
No worries, i’ll prob continue tomorrow or the day after depending on how much in school i have to do tomorrow i truly appreciate your help tho i completely ruined the code trying to move it
TheRanger
TheRangerβ€’2mo ago
its fine we will help you move the rest properly
Unknown User
Unknown Userβ€’2mo ago
Message Not Public
Sign In & Join Server To View
Merineth πŸ‡ΈπŸ‡ͺ
i don’t know what git checkout is
Unknown User
Unknown Userβ€’2mo ago
Message Not Public
Sign In & Join Server To View
Merineth πŸ‡ΈπŸ‡ͺ
no
Unknown User
Unknown Userβ€’2mo ago
Message Not Public
Sign In & Join Server To View
Merineth πŸ‡ΈπŸ‡ͺ
ugh been trying all weekend to fix the mess that was made from last time while trying to move everything to GameManager.cs but now i can't even open visual studio anymore...
Merineth πŸ‡ΈπŸ‡ͺ
i thoguht visual studio is free like vscode
leowest
leowestβ€’2mo ago
community is free enterprise is not so you have to downgrade to community version
Merineth πŸ‡ΈπŸ‡ͺ
oh i must have downloaded the wrong one then
leowest
leowestβ€’2mo ago
No description
leowest
leowestβ€’2mo ago
that is what u have so u probably were using a trial instead of enterprise u want the one that says community
Merineth πŸ‡ΈπŸ‡ͺ
What is Visual Studio Copilot? ai programmer? read about it on a reddit post last night
Unknown User
Unknown Userβ€’2mo ago
Message Not Public
Sign In & Join Server To View
Merineth πŸ‡ΈπŸ‡ͺ
Yeah i managed to get community edition now
Unknown User
Unknown Userβ€’2mo ago
Message Not Public
Sign In & Join Server To View
Merineth πŸ‡ΈπŸ‡ͺ
i tried copilot and it's nice that it explains the error codes i get tho
No description
Merineth πŸ‡ΈπŸ‡ͺ
I managed to resolve all the errors present but when i run the program nothing happens now... i must have broken it completely
TheRanger
TheRangerβ€’2mo ago
nothing happens like, the game window doesnt open?
Unknown User
Unknown Userβ€’2mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiXβ€’2mo ago
If your code is too long, you can post to https://paste.mod.gg/, save, and copy the link into chat for others to see your shared code!
Unknown User
Unknown Userβ€’2mo ago
Message Not Public
Sign In & Join Server To View
TheRanger
TheRangerβ€’2mo ago
he did share his github before
TheRanger
TheRangerβ€’2mo ago
GitHub
GitHub - aljomatrix/Assignment2Repository
Contribute to aljomatrix/Assignment2Repository development by creating an account on GitHub.
Merineth πŸ‡ΈπŸ‡ͺ
The problem i'm facing is that when i click the run and debug button the program closes instantly without anything anything happening anymore
leowest
leowestβ€’2mo ago
look at the bottom failed and errors
Merineth πŸ‡ΈπŸ‡ͺ
So me looking at this is wrong?
No description
TheRanger
TheRangerβ€’2mo ago
πŸ‘€
leowest
leowestβ€’2mo ago
No description
Merineth πŸ‡ΈπŸ‡ͺ
aaah okay there we go, i had to restart my visual studio for it to update
Player player1 = new HumanPlayer(player1Name, Disk.White);
gameManager.player1 = player1;
if (isPlayer2Computer)
{
ComputerPlayer player2;
player2 = new ComputerPlayer(player2Name, Disk.Black);
gameManager.player2 = player2; ;
}
else
{
Player player2;
player2 = new HumanPlayer(player2Name, Disk.Black);
gameManager.player2 = player2;
}


// Create the GameManager instance.
GameManager game = new GameManager(player1, player2);
game.StartGame(GameGridControl);
Player player1 = new HumanPlayer(player1Name, Disk.White);
gameManager.player1 = player1;
if (isPlayer2Computer)
{
ComputerPlayer player2;
player2 = new ComputerPlayer(player2Name, Disk.Black);
gameManager.player2 = player2; ;
}
else
{
Player player2;
player2 = new HumanPlayer(player2Name, Disk.Black);
gameManager.player2 = player2;
}


// Create the GameManager instance.
GameManager game = new GameManager(player1, player2);
game.StartGame(GameGridControl);
Merineth πŸ‡ΈπŸ‡ͺ
How come GameManager wont allow player2 ?
No description
TheRanger
TheRangerβ€’2mo ago
why are u accessing gameManager before creating it well, read the error for us, and we might know why
Merineth πŸ‡ΈπŸ‡ͺ
"The name 'player2' does not exist in the current context"
TheRanger
TheRangerβ€’2mo ago
it only exists in its scope, because you defined it in its scope the variable doesnt exist anymore once it goes out of scope
Merineth πŸ‡ΈπŸ‡ͺ
Ooh right i see what you mean
TheRanger
TheRangerβ€’2mo ago
{ // a scope begins
ComputerPlayer player2 = new();
} // the scope ends
player2.Test(); // player2 doesnt exist anymore
{ // a scope begins
ComputerPlayer player2 = new();
} // the scope ends
player2.Test(); // player2 doesnt exist anymore
Merineth πŸ‡ΈπŸ‡ͺ
Oooh so if i defined Player2 without any more information right before the if statement and then assign it inside the if statement, then it'll exist outside the scope?
TheRanger
TheRangerβ€’2mo ago
yes
Merineth πŸ‡ΈπŸ‡ͺ
Oufh that is tricky. Do you have any hint on how i can go about solving it?
No description
TheRanger
TheRangerβ€’2mo ago
read the error
Merineth πŸ‡ΈπŸ‡ͺ
Yeah player2 has the same problem as before I understand that the arguments it should recieve is either ComputerPlayer2 or HumanPlayer2
TheRanger
TheRangerβ€’2mo ago
why do u have multiple variables for Player2?
Merineth πŸ‡ΈπŸ‡ͺ
the player2 on the 2nd to last line will be replaced With either HumanPlayer2 or ComputerPlayer2
TheRanger
TheRangerβ€’2mo ago
look at Player1
Merineth πŸ‡ΈπŸ‡ͺ
woops! I see what you mean now
Merineth πŸ‡ΈπŸ‡ͺ
I managed to resolve the errors and even managed to add who player1 and player2 are which are currently playing
No description
Merineth πŸ‡ΈπŸ‡ͺ
The only thing i'm completely clueless about tho is making the computer play if it's selected
TheRanger
TheRangerβ€’2mo ago
your GameManager class seems to be useless, it doesnt do anything useful
Merineth πŸ‡ΈπŸ‡ͺ
Yeah i know :( i decided to just leave it as is for now My main goal for now is to make the AI do a proper move
Merineth πŸ‡ΈπŸ‡ͺ
Currently i tried to executeMove to 5,4 which is F5 which is a invalid move
No description
Merineth πŸ‡ΈπŸ‡ͺ
So it throws an exception
TheRanger
TheRangerβ€’2mo ago
what exception? i dont see any exception in the image
Merineth πŸ‡ΈπŸ‡ͺ
Oh sorry one moment
Merineth πŸ‡ΈπŸ‡ͺ
Is it possible to make a while loop perhaps to make it keep trying until a move is found?
leowest
leowestβ€’2mo ago
I mean if the move is not possible why throw just send a messagebox to the user warning them they can't do that move if its ai then just calculate properly the move it has to do it doesnt need to keep trying just make the math right to calculate what places are valid move and pick one
Merineth πŸ‡ΈπŸ‡ͺ
i do have that in place for the human player
internal async Task<(int x, int y)> ExecuteAIMove(GameBoard board)
{
// Get all valid moves for the AI
List<(int x, int y)> validMoves = board.GetValidMoves(_aiDisk);

// If no valid moves, return (-1, -1) to indicate pass
if (validMoves.Count == 0)
{
return (-1, -1);
}

// Simulate AI thinking time (optional)
await Task.Delay(1000);

// Select a move (Basic AI: Random move)
Random random = new Random();
(int x, int y) selectedMove = validMoves[random.Next(validMoves.Count)];

// Execute the move
board.ExecuteMove(selectedMove.x, selectedMove.y, _aiDisk);

// Return the selected move
return selectedMove;
}
internal async Task<(int x, int y)> ExecuteAIMove(GameBoard board)
{
// Get all valid moves for the AI
List<(int x, int y)> validMoves = board.GetValidMoves(_aiDisk);

// If no valid moves, return (-1, -1) to indicate pass
if (validMoves.Count == 0)
{
return (-1, -1);
}

// Simulate AI thinking time (optional)
await Task.Delay(1000);

// Select a move (Basic AI: Random move)
Random random = new Random();
(int x, int y) selectedMove = validMoves[random.Next(validMoves.Count)];

// Execute the move
board.ExecuteMove(selectedMove.x, selectedMove.y, _aiDisk);

// Return the selected move
return selectedMove;
}
This is currently my implementation for the AI move It should get a list of valid moves and return it + exectue it oooooooooh i see what the issue is
Merineth πŸ‡ΈπŸ‡ͺ
the list of valid moves is in fact the valid moves for black, but it should be white
No description
Merineth πŸ‡ΈπŸ‡ͺ
omg IT WORKSSSSS i'm literally in tears right now 😭 I could literally kiss you rn
leowest
leowestβ€’2mo ago
u made it work now u got to make it right learn all the patterns and concepts in the pdf u were given and slowly try to digest it also revisit the c# fundamentals u clearly lacking there a lot you will be very lucky if your teacher doesnt look at the code and I hope he doesnt
Merineth πŸ‡ΈπŸ‡ͺ
I only have one small issue currently. When i press new game while a current game is in session and i input the player1 name and player2 it doesn't reset the gameboard and i have zero ideas how to resolve that But yes i'm aware that my C# knowledge is awful. That course is the worst course i've ever taken to date at Uni (except a math course) This is technically a group project but i've done everything so far I might just let him fix that final part (assuming he still attends the program) so we can call it a 'group project' and turn it in Or would that be something you'd be able to help me with or give me a hint on how to resolve it. Because i have honestly no clue how i can reset the board/game :(
leowest
leowestβ€’2mo ago
imo you have more than enough time to execute it all alone including learning the respective aspects I never said your knowledge is awful just that if u learn the fundamentals properly u will have a much less hard time understanding why a lot of things arent working anyway to reset the board u would have to reset your array to Empty except the initial black and white spots as well as reflecting that in your board
Merineth πŸ‡ΈπŸ‡ͺ
Yeah you are totally right Hmm and that would require resetting the instance of GameBoards array Maybe a new method can be made that does that
leowest
leowestβ€’2mo ago
you see that is the thing if u were using bindings or learned wpf properly or were using mvvm you wouldnt need to duplicate the code u would have one collection representing your board and when that collection changes it would reflect on the board because WPF has a way to notify the ui to update https://wpf-tutorial.com/data-binding/introduction/ this is very superficial but gives you an idea and this one gives u an idea of how it can be used to update a collection of a control as an example https://wpf-tutorial.com/list-controls/itemscontrol/ wpf have many features that makes it a business grade framework it would also reduce a lot of your code you said u had until august if you plan on following the developer's path might be worth taking the time to learn stuff
Merineth πŸ‡ΈπŸ‡ͺ
I absolutely do not have until august to finish this
leowest
leowestβ€’2mo ago
be it for desktop or web u will always be faced with these sort of patterns and concepts school does not prepare u for work
Merineth πŸ‡ΈπŸ‡ͺ
I have to turn this in weeks ago. I don't know how long they take to grade it but it has to be graded and finished before May if i want to proceed to the next year
leowest
leowestβ€’2mo ago
they only give u the tools and knowledge to walk on your own
Merineth πŸ‡ΈπŸ‡ͺ
If i had to time learn wpf, mvvm and everything inbetween i'd do it. But currently i am already very far behind so i mainly want to catch up so i'm not constantly under stress Which means i'm just gonna have to live with my abomination of a code and finish the last piece
private void InitializeBoard()
{
// Clear any existing content (in case of reset)
BoardGrid.Children.Clear();

// Loop through each grid cell and create a tile
for (int row = 0; row < 8; row++)
{
for (int column = 0; column < 8; column++)
{
// Create the tile (Border)
var tile = new Border
{
Background = (row + column) % 2 == 0 ? Brushes.LightGreen : Brushes.DarkGreen, // Alternating green shades
BorderBrush = Brushes.Black,
BorderThickness = new Thickness(1)
};

// Optionally, add an Ellipse for pieces (will be added later in the UpdateBoard method)
tile.Child = new Ellipse
{
Fill = Brushes.Transparent, // Pieces will be added later
Width = 40,
Height = 40,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};

// Set row and column for the grid placement
Grid.SetRow(tile, row);
Grid.SetColumn(tile, column);

// Add the tile to the board grid
BoardGrid.Children.Add(tile);
}
}

// Initialize the 4 starting ones with the right color

}
private void InitializeBoard()
{
// Clear any existing content (in case of reset)
BoardGrid.Children.Clear();

// Loop through each grid cell and create a tile
for (int row = 0; row < 8; row++)
{
for (int column = 0; column < 8; column++)
{
// Create the tile (Border)
var tile = new Border
{
Background = (row + column) % 2 == 0 ? Brushes.LightGreen : Brushes.DarkGreen, // Alternating green shades
BorderBrush = Brushes.Black,
BorderThickness = new Thickness(1)
};

// Optionally, add an Ellipse for pieces (will be added later in the UpdateBoard method)
tile.Child = new Ellipse
{
Fill = Brushes.Transparent, // Pieces will be added later
Width = 40,
Height = 40,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};

// Set row and column for the grid placement
Grid.SetRow(tile, row);
Grid.SetColumn(tile, column);

// Add the tile to the board grid
BoardGrid.Children.Add(tile);
}
}

// Initialize the 4 starting ones with the right color

}
// This method will be called to update the board state dynamically (like placing pieces)
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++)
{
// Find the corresponding Border in the BoardGrid
var tile = BoardGrid.Children[row * 8 + column] as Border;

// Ensure the Border is found and the Child is an Ellipse
var ellipse = tile?.Child as Ellipse;

// Update the Ellipse fill based on the board state
if (ellipse != null)
{
if (boardState[row, column] == Disk.White)
{
ellipse.Fill = Brushes.White; // Set piece to white
}
else if (boardState[row, column] == Disk.Black)
{
ellipse.Fill = Brushes.Black; // Set piece to black
}
else
{
ellipse.Fill = Brushes.Transparent; // Empty cell
}
}
}
}
}
// This method will be called to update the board state dynamically (like placing pieces)
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++)
{
// Find the corresponding Border in the BoardGrid
var tile = BoardGrid.Children[row * 8 + column] as Border;

// Ensure the Border is found and the Child is an Ellipse
var ellipse = tile?.Child as Ellipse;

// Update the Ellipse fill based on the board state
if (ellipse != null)
{
if (boardState[row, column] == Disk.White)
{
ellipse.Fill = Brushes.White; // Set piece to white
}
else if (boardState[row, column] == Disk.Black)
{
ellipse.Fill = Brushes.Black; // Set piece to black
}
else
{
ellipse.Fill = Brushes.Transparent; // Empty cell
}
}
}
}
}
These two functions are the ones that make up my board I'm just not entirely sure how to call the initial state (initializeboard)
leowest
leowestβ€’2mo ago
I mean given how UpdateBoard works I dont think u need another method
Merineth πŸ‡ΈπŸ‡ͺ
I had a brilliant idea
leowest
leowestβ€’2mo ago
just need to set the BoardState of _board and then call UpdateBoard(_board)
Merineth πŸ‡ΈπŸ‡ͺ
Hmmm My idea was to close the window and open a new one and passing the names put in
GameWindow newGameWindow = new GameWindow();
newGameWindow.Show();
this.Close();
GameWindow newGameWindow = new GameWindow();
newGameWindow.Show();
this.Close();
leowest
leowestβ€’2mo ago
you already have the method in there as well resetBoard() so u could just add a new method to the gameboard class that is somewhat
void Initialize()
{
resetBoard();

board[3, 3] = Disk.White;
board[3, 4] = Disk.Black;
board[4, 3] = Disk.Black;
board[4, 4] = Disk.White;
}
void Initialize()
{
resetBoard();

board[3, 3] = Disk.White;
board[3, 4] = Disk.Black;
board[4, 3] = Disk.Black;
board[4, 4] = Disk.White;
}
not ideal no
Merineth πŸ‡ΈπŸ‡ͺ
yeah afaik it's currently unused
leowest
leowestβ€’2mo ago
should be all u need plus passing it to the updateboard or pretty close
Merineth πŸ‡ΈπŸ‡ͺ
Oooh i think i get what you mean
leowest
leowestβ€’2mo ago
so once its game over you have a button play again or something or exit play again would update the board to its initial state
Merineth πŸ‡ΈπŸ‡ͺ
Right i get what you mean quick question tho
Merineth πŸ‡ΈπŸ‡ͺ
I don't want it either black, white or empty
No description
Merineth πŸ‡ΈπŸ‡ͺ
I want it to fill the ellipse with transparant
Merineth πŸ‡ΈπŸ‡ͺ
almost like UpdateBoard does
TheRanger
TheRangerβ€’2mo ago
well, fill the board with an empty disk then tell the UI (by calling the updateBoard method)
Merineth πŸ‡ΈπŸ‡ͺ
Hi R!
Merineth πŸ‡ΈπŸ‡ͺ
(So ignoring the errors) something like this?
No description
TheRanger
TheRangerβ€’2mo ago
thats not how u call a method, where did you define the resetboard method?
Merineth πŸ‡ΈπŸ‡ͺ
It's currently defined in GameBoard So if i were to call UpdateBoard it'd be outside scope
TheRanger
TheRangerβ€’2mo ago
and where is the UpdateBoard method defined?
Merineth πŸ‡ΈπŸ‡ͺ
UpdateBoard is in GameGrid ResetBoard is in GameBoard Maybe moving the reset method to the GameGrid would make it work?
TheRanger
TheRangerβ€’2mo ago
professionally the ResetBoard should be in the board class it is recommended to encapsulate your data as much as you can
Merineth πŸ‡ΈπŸ‡ͺ
I completely forgot what encapsulate meant
TheRanger
TheRangerβ€’2mo ago
google it
Merineth πŸ‡ΈπŸ‡ͺ
will do, one sec
TheRanger
TheRangerβ€’2mo ago
Encapsulation (computer programming)
In software systems, encapsulation refers to the bundling of data with the mechanisms or methods that operate on the data. It may also refer to the limiting of direct access to some of that data, such as an object's components. Essentially, encapsulation prevents external code from being concerned with the internal workings of an object. Encaps...
Merineth πŸ‡ΈπŸ‡ͺ
Oh so if i understand it correctly the goal is to make sure fields/attributes/methods should be under a single class?
TheRanger
TheRangerβ€’2mo ago
+ A language mechanism for restricting direct access to some of the object's components.
+ A language construct that facilitates the bundling of data with the methods (or other functions) operating on those data.
+ A language mechanism for restricting direct access to some of the object's components.
+ A language construct that facilitates the bundling of data with the methods (or other functions) operating on those data.
dont let the for example the GameBoard window reset the board directly, let the GameBoard tell The Board to reset itself the GameBoard's main objective is to just render if you have a dog class for example, dont let a human make its legs walk, let the human command the dog to walk so basically ur GameBoard window should not reset the board directly, it should only command the Board to reset itself
Merineth πŸ‡ΈπŸ‡ͺ
Hmm i think i get what you mean But thinking of encpauslation made me completely forget what i was trying to do lol 1. NewGameButton_Click is pressed 2. the user inputs player names 3. user presses ok 4. the board is reset in that order i guess Currently 1-3 work but it isn't being reset
TheRanger
TheRangerβ€’2mo ago
u pretty much encapsulated many data i just checked ur github, the resetBoard is actually in The GameBoard class (i thought it was called Board) nvm so u did it fine are u calling the ResetBoard method from anywhere? doesnt seem so
Merineth πŸ‡ΈπŸ‡ͺ
Hmmmm i'm trying to digest what i'm trying to accomplish Let me push my changes also Ok i have pushed my recent changes I assume i want to call reset board at the end of the NewGameButton_click?
private void NewGameButton_Click(object sender, RoutedEventArgs e)
{
// Show the SetUpGameDialog to collect player names and types
SetUpGameDialog setUpDialog = new SetUpGameDialog();
bool? result = setUpDialog.ShowDialog(); // Show dialog and wait for result
if (result == true) // If OK was clicked (DialogResult = true)
{
// Retrieve player names and player types
string player1Name = setUpDialog.Player1Name;
string player2Name = setUpDialog.Player2Name;
bool isPlayer2Computer = setUpDialog.IsPlayer2Computer;

// Creates 3 instances for the if statement. player 1 is always human
// so i always creater player1 as HumanPlayer and the if determines if it's computer or human.
Player player1 = new HumanPlayer(player1Name, Disk.White);
Player player2 = isPlayer2Computer ? new ComputerPlayer(player2Name, Disk.Black) : new HumanPlayer(player2Name, Disk.Black);

// Create the GameManager instance.
gameManager = new GameManager(player1, player2);

// Set player names in the UI
Player1NameTextBlock.Text = $"Player 1: {player1Name}";
Player2NameTextBlock.Text = $"Player 2: {player2Name}";

// Initialize the GameGrid with the isPlayer2Computer flag
GameGridControl._isPlayer2Computer = isPlayer2Computer;
if (isPlayer2Computer)
{
GameGridControl._computerPlayer = (ComputerPlayer)player2;
}
gameManager.StartGame(GameGridControl);

}
else
{
// If the user cancels the setup
MessageBox.Show("Game setup was canceled.", "Canceled");
}
}
private void NewGameButton_Click(object sender, RoutedEventArgs e)
{
// Show the SetUpGameDialog to collect player names and types
SetUpGameDialog setUpDialog = new SetUpGameDialog();
bool? result = setUpDialog.ShowDialog(); // Show dialog and wait for result
if (result == true) // If OK was clicked (DialogResult = true)
{
// Retrieve player names and player types
string player1Name = setUpDialog.Player1Name;
string player2Name = setUpDialog.Player2Name;
bool isPlayer2Computer = setUpDialog.IsPlayer2Computer;

// Creates 3 instances for the if statement. player 1 is always human
// so i always creater player1 as HumanPlayer and the if determines if it's computer or human.
Player player1 = new HumanPlayer(player1Name, Disk.White);
Player player2 = isPlayer2Computer ? new ComputerPlayer(player2Name, Disk.Black) : new HumanPlayer(player2Name, Disk.Black);

// Create the GameManager instance.
gameManager = new GameManager(player1, player2);

// Set player names in the UI
Player1NameTextBlock.Text = $"Player 1: {player1Name}";
Player2NameTextBlock.Text = $"Player 2: {player2Name}";

// Initialize the GameGrid with the isPlayer2Computer flag
GameGridControl._isPlayer2Computer = isPlayer2Computer;
if (isPlayer2Computer)
{
GameGridControl._computerPlayer = (ComputerPlayer)player2;
}
gameManager.StartGame(GameGridControl);

}
else
{
// If the user cancels the setup
MessageBox.Show("Game setup was canceled.", "Canceled");
}
}
But the resetboard() method in Gameboard.cs doesn't reset the board afaik? 😭
Merineth πŸ‡ΈπŸ‡ͺ
Sat with it for like an hour now but i can't seem to resolve the issue I've managed to make it reset the appearance of the board but the backend still thinks the same board is in play.. and i have literally 0 idea how to solve it
leowest
leowestβ€’2mo ago
well yeah you're using 2 different instances of GameBoard thats why using gpt is no good it doesnt have context of your code to be able to know where things need to go and more
Merineth πŸ‡ΈπŸ‡ͺ
i’m doing the best i can πŸ˜” Was that it? xD roast me for using gpt and nothing else 😢
leowest
leowestβ€’2mo ago
yes that is it for me, sorry I dont have much will to help people that arent even trying or want to learn, but perhaps the others might want to still try.
Merineth πŸ‡ΈπŸ‡ͺ
You have some serious issues Imagine having the audacity to willingly join a C# discord to help people and then you go around not giving a single piece of help but instead nag about people using chatgpt or how terrible they are at programming. Should be ashamed of yourself
TheRanger
TheRangerβ€’2mo ago
hmm lets track this, u clicked a new game, it asks for ur players names again
Merineth πŸ‡ΈπŸ‡ͺ
Yeah so i click new game, input names of both players and then the UI visually updates to the start like it does on this video but it seems like even if they are filled with transparant color the current game is still ongoing
TheRanger
TheRangerβ€’2mo ago
looks like u only reset the board in the UI but not in the back end
Merineth πŸ‡ΈπŸ‡ͺ
Yeah exactly, i'm not sure which instance governs that I've tried debugging it but it's tricky
TheRanger
TheRangerβ€’2mo ago
i see whats going on
Merineth πŸ‡ΈπŸ‡ͺ
You do?! :O
TheRanger
TheRangerβ€’2mo ago
you only reset the board in the UI but not in the back end they have to be in sync u know when you click the New game button it calls the NewGameButton_Click in the GameWindow.xaml.cs
Merineth πŸ‡ΈπŸ‡ͺ
Yeah
TheRanger
TheRangerβ€’2mo ago
guess what line 61 does
Merineth πŸ‡ΈπŸ‡ͺ
It starts the dialog for the new window? bool? result = setUpDialog.ShowDialog(); // Show dialog and wait for result i assume you mean this line 61?
TheRanger
TheRangerβ€’2mo ago
yes but, what new window? yeah
Merineth πŸ‡ΈπŸ‡ͺ
It's the instance of SetUpGameDialog
TheRanger
TheRangerβ€’2mo ago
correct, who's code is SetupGameDialog.xaml.cs
Merineth πŸ‡ΈπŸ‡ͺ
Could it be GameGrid gameGrid = new GameGrid();?
TheRanger
TheRangerβ€’2mo ago
no we said SetUpGameDialog SetUpGameDialog asks for player's names
Merineth πŸ‡ΈπŸ‡ͺ
Right
TheRanger
TheRangerβ€’2mo ago
now what happens, when you click ok after u put the players' names?
Merineth πŸ‡ΈπŸ‡ͺ
it will be saved as a bool? no it will save player1 and player2s name under string player1Name = setUpDialog.Player1Name; string player2Name = setUpDialog.Player2Name; Hmm let me double check, one moment
private void OKButton_Click(object sender, RoutedEventArgs e)
{
// Capture the player names and check if Player 2 is a computer
Player1Name = Player1NameTextBox.Text;
IsPlayer2Computer = (bool)IsPlayer2ComputerCheckBox.IsChecked; // Get checkbox value

if (IsPlayer2Computer)
{
Player2Name = "Computer"; // Auto-set name
}
else
{
Player2Name = Player2NameTextBox.Text;
}

// Ensure player names are provided
if (string.IsNullOrEmpty(Player1Name) || (!IsPlayer2Computer && string.IsNullOrEmpty(Player2Name)))
{
MessageBox.Show("Please enter names for both players.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

// Start the game and pass IsPlayer2Computer to GameGrid
GameGrid gameGrid = new GameGrid();
if (IsPlayer2Computer)
{
gameGrid._isPlayer2Computer = true;
}
// Set the dialog result and close
this.DialogResult = true;
this.Close();
}
private void OKButton_Click(object sender, RoutedEventArgs e)
{
// Capture the player names and check if Player 2 is a computer
Player1Name = Player1NameTextBox.Text;
IsPlayer2Computer = (bool)IsPlayer2ComputerCheckBox.IsChecked; // Get checkbox value

if (IsPlayer2Computer)
{
Player2Name = "Computer"; // Auto-set name
}
else
{
Player2Name = Player2NameTextBox.Text;
}

// Ensure player names are provided
if (string.IsNullOrEmpty(Player1Name) || (!IsPlayer2Computer && string.IsNullOrEmpty(Player2Name)))
{
MessageBox.Show("Please enter names for both players.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

// Start the game and pass IsPlayer2Computer to GameGrid
GameGrid gameGrid = new GameGrid();
if (IsPlayer2Computer)
{
gameGrid._isPlayer2Computer = true;
}
// Set the dialog result and close
this.DialogResult = true;
this.Close();
}
I assigns Player1Name and the player2name. Then it creates a new instance of GameGrid and closes the window And that's basically it?
TheRanger
TheRangerβ€’2mo ago
took me a while to find ur GameManager.cs, it should be in the Model folder
Merineth πŸ‡ΈπŸ‡ͺ
Yeah sorry my file management in this project is a catastrophe :catderp:
TheRanger
TheRangerβ€’2mo ago
so back to the setupgamedialog when u click ok, it closes the setupgamedialog, and returns true, right?
Merineth πŸ‡ΈπŸ‡ͺ
Yeah
TheRanger
TheRangerβ€’2mo ago
so back to line 61 in GameWindow.xaml.cs, the true returned will be assigned to bool? result in line 61
Merineth πŸ‡ΈπŸ‡ͺ
Yeah that gets set to true
TheRanger
TheRangerβ€’2mo ago
it initializes the player and put their names then initializes a new GameManager in line 75 correct?
Merineth πŸ‡ΈπŸ‡ͺ
Yeah, makes sense so far!
TheRanger
TheRangerβ€’2mo ago
so then, what does line 87 do?
Merineth πŸ‡ΈπŸ‡ͺ
It calls the method
public void StartGame(GameGrid gameGridControl)
{
gameGridControl.UpdateBoard(_board.BoardState);
}
public void StartGame(GameGrid gameGridControl)
{
gameGridControl.UpdateBoard(_board.BoardState);
}
which updates the board
TheRanger
TheRangerβ€’2mo ago
correct
Merineth πŸ‡ΈπŸ‡ͺ
Could it be that it's passing the wrong argument?
TheRanger
TheRangerβ€’2mo ago
but which board tho
Merineth πŸ‡ΈπŸ‡ͺ
It's currently passing GameGridControl Let me check No wait the updateboard is passing _board is it supposed to pass gameManager from line 75 perhaps?
TheRanger
TheRangerβ€’2mo ago
thats not the issue u created a new board in game manager correct? when u create a new GameManager instance, it creates a new board, then assigns its reference to _board in that GameManager instance
Merineth πŸ‡ΈπŸ‡ͺ
Right yeah that makes sense based on line 22 in GameManager.cs?
TheRanger
TheRangerβ€’2mo ago
yes now, when line 32 in GameManager.cs gets called it shows you the UI of the board stored in _board in the GameManager instance
Merineth πŸ‡ΈπŸ‡ͺ
right
TheRanger
TheRangerβ€’2mo ago
But when you click with your mouse on the board it does not check with that board stored in the GameManager it checks with the board stored in _board in the GameGrid class who has a different board as u can see in line 22 in GameGrid.xaml.cs so basically, u created 2 boards,
Merineth πŸ‡ΈπŸ‡ͺ
so the _board in gamegrid and _board in gamemanager aren't the same
TheRanger
TheRangerβ€’2mo ago
they are not refering to the same board, yeah
Merineth πŸ‡ΈπŸ‡ͺ
Oufh no wonder i had a hard time digesting what's happening lol So basically the goal is to reset the _board in GameGrid also
TheRanger
TheRangerβ€’2mo ago
No then again ull have 2 boards, but just the 2 of them will be empty, lol
Merineth πŸ‡ΈπŸ‡ͺ
I see
TheRanger
TheRangerβ€’2mo ago
new GameBoard() means u created a new board var foo = new GameBoard(); means foo is refering to that new GameBoard()
var foo = new GameBoard();
var bar = foo;
var qaaz = foo;
var foo = new GameBoard();
var bar = foo;
var qaaz = foo;
means the 3 variables are refering to the same board
Merineth πŸ‡ΈπŸ‡ͺ
That makes sense
TheRanger
TheRangerβ€’2mo ago
when u want to create a new gameboard, u should only create it once, and let 1 or more variables refer to it
Merineth πŸ‡ΈπŸ‡ͺ
I see So we want to remove the creation of gameboard from gamegrid and instead reference the _board from gameboard.cs?
TheRanger
TheRangerβ€’2mo ago
u can let _board in GameGrid refer to the board stored in GameManager yeah but its unprofessional you should basically just access the gameManager instance instead since it has everything related to the game grouped in 1 class
Merineth πŸ‡ΈπŸ‡ͺ
Oh i see, is it possible to reference the gameManager instance instead in GameGrid? Or do i have it twisted? So far i'm totally with you that _board in GameManager and GameGrid are two totally different instances of board And currently it's only resetting the _board in GameManager and leaving the _board in gamegrid alone Which results in it thinking that we are still currently on the same game
TheRanger
TheRangerβ€’2mo ago
var foo = new GameBoard();
var bar = foo;
foo = null;
bar.ResetBoard();
var foo = new GameBoard();
var bar = foo;
foo = null;
bar.ResetBoard();
^ can u tell me what happened here
Merineth πŸ‡ΈπŸ‡ͺ
bar.ResetBoard(); does nothing since bar is already set to null
TheRanger
TheRangerβ€’2mo ago
wrong
Merineth πŸ‡ΈπŸ‡ͺ
o.o
TheRanger
TheRangerβ€’2mo ago
new GameBoard(); gets stored somewhere , lets say an invisible variable
Merineth πŸ‡ΈπŸ‡ͺ
Is it because bar doesn't update dynamically when foo changes?
TheRanger
TheRangerβ€’2mo ago
foo looks at that invisible variable and bar looks at that invisible variable that it took from foo then foo became null, but doesnt affect bar cuz it already knows what invisible variable to look at
Merineth πŸ‡ΈπŸ‡ͺ
Hmm so foo stores a gameboard bar becomes a copy? that's a very tricky concept
TheRanger
TheRangerβ€’2mo ago
foo doesnt store a gameboard it stores its reference the gameboard is stored in an invisible variable ur just telling foo what invisible variable to look at then foo told bar what to look at then foo doesnt look at it anymore but bar still does, it already knows what board to look at say, u are walking with a friend in a street he saw a red bmw
Merineth πŸ‡ΈπŸ‡ͺ
ooh so foo stores a gameboard bar stores the reference of foo foo gets set to null bar.resetboard sets the gameboard to reset`?
TheRanger
TheRangerβ€’2mo ago
No foo does not store a gameboard
Merineth πŸ‡ΈπŸ‡ͺ
So we are not talking pointers from C?
TheRanger
TheRangerβ€’2mo ago
it stores its refernce if you know C, that makes it easier yes, foo is a pointer
Merineth πŸ‡ΈπŸ‡ͺ
Right but passing a pointer you are able to change what foo is storing
TheRanger
TheRangerβ€’2mo ago
1 - new Gameboard gets created 2 - foo points to that gameboard 3 - foo told bar to point at it too 4 - foo does not point anymore (but bar still does) 5 - bar called ResetBoard() method at the board its pointing to
Merineth πŸ‡ΈπŸ‡ͺ
aaaahh that makes sense Yeah i see what u mean
TheRanger
TheRangerβ€’2mo ago
itd behave differently if GameBoard is a struct instead of class but we dont have to worry about that for now
Merineth πŸ‡ΈπŸ‡ͺ
My intuition tells me that we want to pass a reference to GameGrid? Might be wrong tho
TheRanger
TheRangerβ€’2mo ago
again u can let _board in gamemanager and in gamegrid point to the same board, but its unprofessional, since you can just access the gamemanager instance in the GameGrid itself
Merineth πŸ‡ΈπŸ‡ͺ
Ohh wait i think i'm getting at what you mean so we make a get of the instance in gamemanager? and grab it from both GameManager and GameGrid?
TheRanger
TheRangerβ€’2mo ago
the main purpose of GameManager is to group everything related to the game into 1 class The Players, the board, etc... Grab instance of gameManager from GameManager? that doesnt make sense πŸ˜…
Merineth πŸ‡ΈπŸ‡ͺ
hahah Well mainly get for GameGrid :Smadge: haha i'm so lost
TheRanger
TheRangerβ€’2mo ago
what does ur pdf say?
Merineth πŸ‡ΈπŸ‡ͺ
I'll try and summarise the problem So currently the GameManager is passing _board which is not the same as the _board from GameGrid, correct?
TheRanger
TheRangerβ€’2mo ago
theyre not pointing to the same instance of GameBoard, yes honestly i think it might be easier to create a GameManager field in the GameGrid class you wont have to worry about cant accessing it in the GameWindow class since you can just access it through GameGridControl variable
Merineth πŸ‡ΈπŸ‡ͺ
private GameManager _gameManager; So i add this to the start of the GameGrid class Does it need attributes to set ?
TheRanger
TheRangerβ€’2mo ago
yeah, now
public bool _isPlayer2Computer;
private Disk _currentPlayerDisk = Disk.Black;
public ComputerPlayer _computerPlayer;
public bool _isPlayer2Computer;
private Disk _currentPlayerDisk = Disk.Black;
public ComputerPlayer _computerPlayer;
are related, so better put them into the gamemanager class _computerPlayer is useless, should be deleted and _isPlayer2Computer useless too
Merineth πŸ‡ΈπŸ‡ͺ
But they are being used? for my bool if statement
TheRanger
TheRangerβ€’2mo ago
it is recommended that fields should not be accessed from outside its class create a method, or a property for it public bool IsPlayer2Computer => _player2 is ComputerPlayer; a simple property that checks if player2 is an instance of ComputerPlayer easy, right? there's a reason we put _ before a fields name, to indicate to us that this is a field and its unprofessional to make it public
Merineth πŸ‡ΈπŸ‡ͺ
If i remove those two fields i get tons of errors, i'm not sure i dare to do that
TheRanger
TheRangerβ€’2mo ago
no worries we can fix it
Merineth πŸ‡ΈπŸ‡ͺ
hm ok
Merineth πŸ‡ΈπŸ‡ͺ
i guess we have to create player2 first?
TheRanger
TheRangerβ€’2mo ago
we said group everything related to the game to GameManager so the _board and _currentPlayerDisk should be moved to the GameManager class
Merineth πŸ‡ΈπŸ‡ͺ
I have literally zero idea how to move and split up code into a new class My only goal right now is to try and digest what the issue is and find a solution And i don't know how to pass arguments between classes
TheRanger
TheRangerβ€’2mo ago
what arguments are u trying to pass?
Merineth πŸ‡ΈπŸ‡ͺ
I'm trying to make _board from GameGrid and GameManager to reference the same thing so that when we reset it resets both front end and back end I'm physically unable to go through hundreds of lines of code to move them to GameManager like the pdf suggests
TheRanger
TheRangerβ€’2mo ago
what did i say here if u have _board field in GameManager and u have GameManager field in GameGrid, why would you need the _board field in the GameGrid
Merineth πŸ‡ΈπŸ‡ͺ
I don't know.. in my attempts to fix it i just made it worse fml
TheRanger
TheRangerβ€’2mo ago
its totally normal to make mistakes and learn from them, thats what makes us better programmers why create _player2 when its stored in _gameManager
Merineth πŸ‡ΈπŸ‡ͺ
ok i managed to reverse everything i did and i'm back to where we were Like i understand the problem i just don't have a clue on how to resolve it When
public void StartGame(GameGrid gameGridControl)
{
gameGridControl.UpdateBoard(_board.BoardState);
}
public void StartGame(GameGrid gameGridControl)
{
gameGridControl.UpdateBoard(_board.BoardState);
}
is called. The problem is that it's passing _board from GameManager but we also want it to pass _board from GameGrid Is that correct? Because moving everything that has to do with the GameManager into GameManager is like a weeks effort for me There must be an easier way
TheRanger
TheRangerβ€’2mo ago
why did you reserve? what i recommended is the easiest way it doesnt take few minutes tbh, especially when im helping with you put back _gameManager, remove _currentPlayerDisk and _board and IsPlayer2Computer
Merineth πŸ‡ΈπŸ‡ͺ
Ok that gave me 23 errors
TheRanger
TheRangerβ€’2mo ago
errors sometimes doesnt matter a 1000 error can be fixed in a second and sometimes a 10 error can take hours to get fixed it depends
Merineth πŸ‡ΈπŸ‡ͺ
i see
TheRanger
TheRangerβ€’2mo ago
in ur case these errors are easy fixable remove public ComputerPlayer _computerPlayer
Merineth πŸ‡ΈπŸ‡ͺ
ok
TheRanger
TheRangerβ€’2mo ago
remove those 2, cuz gamemanager is now responsible for them
No description
TheRanger
TheRangerβ€’2mo ago
pretend GameManager is a human that you talk to
Merineth πŸ‡ΈπŸ‡ͺ
ok _board in gamegrid constructor also?
TheRanger
TheRangerβ€’2mo ago
unneeded
Merineth πŸ‡ΈπŸ‡ͺ
unneeded as in remove it?
TheRanger
TheRangerβ€’2mo ago
gameManager is already responsible for it, yeah
Merineth πŸ‡ΈπŸ‡ͺ
roger that what happens with updateboard since we have no _board to reference?
TheRanger
TheRangerβ€’2mo ago
we do have a reference to board that reference is stored in _gameManager
Merineth πŸ‡ΈπŸ‡ͺ
the getboard() method?
TheRanger
TheRangerβ€’2mo ago
UpdateBoard(_gameManager._board); but again _board is a field it should be private, so create a getter for it yeah but in C# we use properties for that
Merineth πŸ‡ΈπŸ‡ͺ
The getter should be made in GameManager?
TheRanger
TheRangerβ€’2mo ago
Yeah public Board[,] Board => _board; thats a getter only property
Merineth πŸ‡ΈπŸ‡ͺ
private GameBoard _board { get; } so that is wrong?
TheRanger
TheRangerβ€’2mo ago
u already have a field called _board tho
Merineth πŸ‡ΈπŸ‡ͺ
No i'm trying to follow ur instructions
TheRanger
TheRangerβ€’2mo ago
public GameBoard Board => _board; u need to specify what to return ur talking to the gamemanager, ur asking them to give you the GameBoard instace
TheRanger
TheRangerβ€’2mo ago
i made a mistake, read this again this is equivalent to public GameBoard getBoard() if you did java before or C
Merineth πŸ‡ΈπŸ‡ͺ
i'm not sure i understand
TheRanger
TheRangerβ€’2mo ago
its simple the UpdateBoard method wants a Disk[,] argument not GameBoard u can either get the Disk[,] from the GameBoard instance or Change the Type of the UpdateBoard's parameter do u knw how to get the Disk[,] instance from the GameBoard instance?
Merineth πŸ‡ΈπŸ‡ͺ
this would be my guess but it's just a guess
TheRanger
TheRangerβ€’2mo ago
voila
Merineth πŸ‡ΈπŸ‡ͺ
but it's expecting two arguments Disk[] and boardstate
TheRanger
TheRangerβ€’2mo ago
who expects 2 arguments?
Merineth πŸ‡ΈπŸ‡ͺ
nvm sorry It's one argument disk[] boardstate I applied the same method to the one below
TheRanger
TheRangerβ€’2mo ago
Note: i like following the law of demeter, like i hate accessing a method through another Method i would write it like this UpdateBoard(_gameManager.BoardState); where BoardState is a getter that gets an instance of BoardState from GameBoard instance public BoardState BoardState => _board.BoardState;
Merineth πŸ‡ΈπŸ‡ͺ
so how do i go about solving these
No description
Merineth πŸ‡ΈπŸ‡ͺ
change _board from the _gamemanager?
TheRanger
TheRangerβ€’2mo ago
Encapsulation if (_gameManager.IsValidMove(row, column)) where ofcourse this method will call _board.IsValidMove(row, column, _currentPlayerDisk); see how easy things went, and very readable even makes it easy for another programmer if they took over ur project
Merineth πŸ‡ΈπŸ‡ͺ
i had to add.Board for it to work
TheRanger
TheRangerβ€’2mo ago
you did not read my message well read again
Merineth πŸ‡ΈπŸ‡ͺ
You mean the law of demeter?
TheRanger
TheRangerβ€’2mo ago
this one
TheRanger
TheRangerβ€’2mo ago
isnt this obvious? create the method!!! say a user is pointing at a cell and asking if its a validmove, the user should not know who's turn is it, the gamemanager does
Merineth πŸ‡ΈπŸ‡ͺ
So i move the Isvalidmove from gameboard to gamemanager?
TheRanger
TheRangerβ€’2mo ago
No keep it i think u cant read my messages well basically the gamemanager's IsValidMove will call the GameBoard's IsValidMove
Merineth πŸ‡ΈπŸ‡ͺ
No i've been at this for 12+ hours i'm dizzy and it's getting hard to read
TheRanger
TheRangerβ€’2mo ago
because who can only see the _currentPlayerDIsk variable? its the gamemanager
Merineth πŸ‡ΈπŸ‡ͺ
So i'm supposed to create a whole new implementation for isvalid move in the GameManager?
public bool IsValidMove(int row, int column)
{

}
public bool IsValidMove(int row, int column)
{

}
TheRanger
TheRangerβ€’2mo ago
yeah and it will call _board's IsValidMove
Merineth πŸ‡ΈπŸ‡ͺ
public bool IsValidMove(int row, int column) { return _board.IsValidMove(row, column, _board...........); } so like this?
TheRanger
TheRangerβ€’2mo ago
what is _board...........
Merineth πŸ‡ΈπŸ‡ͺ
unfinished implementation
TheRanger
TheRangerβ€’2mo ago
you should know what argument the _board's IsValidMove expects its expecting _currentPlayerDIsk, right?
Merineth πŸ‡ΈπŸ‡ͺ
Right so either white or black
TheRanger
TheRangerβ€’2mo ago
you did move _currentPlayerDIsk to the GameManager class, right?
Merineth πŸ‡ΈπŸ‡ͺ
no?
Merineth πŸ‡ΈπŸ‡ͺ
this is the only currentplayuerdisk i have
TheRanger
TheRangerβ€’2mo ago
where is this?
Merineth πŸ‡ΈπŸ‡ͺ
from gameGrid
TheRanger
TheRangerβ€’2mo ago
gamemanager should be responsible for switching turns hes the manager after all
Merineth πŸ‡ΈπŸ‡ͺ
i have no other implementation of _currentplayerdisk
TheRanger
TheRangerβ€’2mo ago
well implement one in the GameManager class then!!!!!! he's the referee
Merineth πŸ‡ΈπŸ‡ͺ
I get that but it's not as easy as you make it sound
TheRanger
TheRangerβ€’2mo ago
its definitely easy
Merineth πŸ‡ΈπŸ‡ͺ
like im super novice to c# it takess a really long time for me to understand
TheRanger
TheRangerβ€’2mo ago
are u aiming to became a programmer in the future? or is this just a school project that is mandatory to do
Merineth πŸ‡ΈπŸ‡ͺ
hell no i fucking hate c# i'm never touching this in my life again this is making me suicidal
TheRanger
TheRangerβ€’2mo ago
which language do u prefer
Merineth πŸ‡ΈπŸ‡ͺ
i don't know anymore c# has completely ruined my feelings for programming like it might be easy for you to move everything to gamemanger but this will take me 10s of hours
TheRanger
TheRangerβ€’2mo ago
u havent answered my question tho are u aiming to became a programmer in the future? or is this just a school project that is mandatory to do
Merineth πŸ‡ΈπŸ‡ͺ
it's a mandatory course in the program
TheRanger
TheRangerβ€’2mo ago
i see so ur not aiming to become a programmer then
Merineth πŸ‡ΈπŸ‡ͺ
Very unlikely anymore
TheRanger
TheRangerβ€’2mo ago
in GameManager class define a field private Disk _currentPlayerDisk; only the GameManager aka Referee can change the turns he's responsible for switching turns
Merineth πŸ‡ΈπŸ‡ͺ
makes sense
TheRanger
TheRangerβ€’2mo ago
that wasnt hard, was it?
Merineth πŸ‡ΈπŸ‡ͺ
No
TheRanger
TheRangerβ€’2mo ago
the referee is the one that tells u if this cell is valid move, and he answers depending on who's turn is it
Merineth πŸ‡ΈπŸ‡ͺ
So i guess the entire if statement from GameGrid_mousedown is moved to GameManager?
No description
Merineth πŸ‡ΈπŸ‡ͺ
since it reolves around placing pieces on the board? i.e make a method for it?
TheRanger
TheRangerβ€’2mo ago
well yeah you can u can define a method in the GameManager class and call it public bool Click(int row, int column) that will carry this if condition but since there's an async method, u can make the return type public async Task<bool> Click(int row, int column)
Merineth πŸ‡ΈπŸ‡ͺ
Yeah i'm trying
Merineth πŸ‡ΈπŸ‡ͺ
But it's taking years trying to resolve errors and getting new ones Now it wants an updateboard so i'm gonna have to implement that aswell Do i just copy the UpdateBoard from Boardgrid? or do i remake it completely and make is async
TheRanger
TheRangerβ€’2mo ago
no worries game manager is responsible for switching turns so move the toggleplayerturn to it
Merineth πŸ‡ΈπŸ‡ͺ
Hmm I can't find my implementaiton for toggleplayerturn we removed it Ok i found it That resolved one error, nice
Merineth πŸ‡ΈπŸ‡ͺ
I have no implementation of updateboard so i guess i have to move it there?
TheRanger
TheRangerβ€’2mo ago
No, we will get to that later
Merineth πŸ‡ΈπŸ‡ͺ
okie Ok i managed to solve
Merineth πŸ‡ΈπŸ‡ͺ
the if statement i think the rest of the errors are update board and async should i change the method to async? it did resolve the awai errors so seems to be it
TheRanger
TheRangerβ€’2mo ago
public async Task<bool> ExecuteMov......... ur gonna need to return a boolean here
Merineth πŸ‡ΈπŸ‡ͺ
roger that
Merineth πŸ‡ΈπŸ‡ͺ
Seems to be proper now
TheRanger
TheRangerβ€’2mo ago
honestly the computer move should be in a different method but lets save that for later
Merineth πŸ‡ΈπŸ‡ͺ
Yeah i see what you mean
TheRanger
TheRangerβ€’2mo ago
ExecuteAIMove is only defined in the ComputerPlayer class, right?
Merineth πŸ‡ΈπŸ‡ͺ
yes Only defined in ComputerPlayer
TheRanger
TheRangerβ€’2mo ago
then if u replaced if(_player2 is ComputerPlayer) with if(_player2 is ComputerPlayer computer) it will create a variable pointing to player2 and sees it as ComputerPlayer cuz you know, its actually ComputerPlayer in the memory
Merineth πŸ‡ΈπŸ‡ͺ
I see
TheRanger
TheRangerβ€’2mo ago
like casting Animal to Cat
Merineth πŸ‡ΈπŸ‡ͺ
Do we ideally want to move ExecuteAIMove to GameManager so it's accessible?
No description
TheRanger
TheRangerβ€’2mo ago
think for 1 second on what to do in the first error just think 1 second
Merineth πŸ‡ΈπŸ‡ͺ
:catlaugh:
No description
TheRanger
TheRangerβ€’2mo ago
bingo ur laughing, are u starting to love programming?
Merineth πŸ‡ΈπŸ‡ͺ
It certainly is 10x more fun when i actually understand what i'm doing
TheRanger
TheRangerβ€’2mo ago
suffering then solving problems in programming is what makes us love programming
Merineth πŸ‡ΈπŸ‡ͺ
It's like a huge pendulum swinging from suicide to ecstasy lol
TheRanger
TheRangerβ€’2mo ago
yeah emotions are like a bouncing ball if the ball falls too hard, it will bounce back higher
Merineth πŸ‡ΈπŸ‡ͺ
We are down to only 7 errors left 😎 Did you have a solution in mind for how to fix UpdateBoard?
TheRanger
TheRangerβ€’2mo ago
delegate like the pdf says delegate is something like this
Merineth πŸ‡ΈπŸ‡ͺ
delegates were the #1 thing our entire class struggled with completely incomprehensible
TheRanger
TheRangerβ€’2mo ago
void Foo()
{
Console.WriteLine("I am foo");
}
void Bar()
{
Console.WriteLine("I am bar");
}
void Qaaz()
{
Console.WriteLine("I am qaaz");
}

Action method = Foo;
method(); // prints i am foo

method = Bar;
method(); // prints i am bar

method = Qaaz;
method(); // prints i am qaaz
void Foo()
{
Console.WriteLine("I am foo");
}
void Bar()
{
Console.WriteLine("I am bar");
}
void Qaaz()
{
Console.WriteLine("I am qaaz");
}

Action method = Foo;
method(); // prints i am foo

method = Bar;
method(); // prints i am bar

method = Qaaz;
method(); // prints i am qaaz
Merineth πŸ‡ΈπŸ‡ͺ
so one method does several things?
TheRanger
TheRangerβ€’2mo ago
its a pointer points to a method u just tell it which method to point at
Merineth πŸ‡ΈπŸ‡ͺ
hmm
TheRanger
TheRangerβ€’2mo ago
u could start by defining a field in the GameManager class
public Action UpdateBoard;
public Action UpdateBoard;
Merineth πŸ‡ΈπŸ‡ͺ
Action is syntax specific for delegates?
TheRanger
TheRangerβ€’2mo ago
points at parameterless methods, yes theres another way to define a delegate public delegate void UpdateBoard;
Merineth πŸ‡ΈπŸ‡ͺ
right the word delegate is something we went through
TheRanger
TheRangerβ€’2mo ago
yeah better use that
Merineth πŸ‡ΈπŸ‡ͺ
One way to do this is to use delegates/events, so that a view-class can register a callback method with the GameManager when a new game session is started. The GameManager can then invoke the delegate each time it needs to inform the GUI about game state changes (and can pass any necessary information to the callback method). Although, we don’t want to pass the GameBoard directly to the callback method, but only e.g. an 8x8 matrix representing the GameBoard’s state.
is this the part you mentionded from the pdf? public delegate void UpdateBoard(); like so?
TheRanger
TheRangerβ€’2mo ago
public delegate void UpdateBoard(Board[,] board]; so that it can accept the UpdateBoard method with that parameter that is defined in the GameGrid clas
Merineth πŸ‡ΈπŸ‡ͺ
So i don't make a field?
TheRanger
TheRangerβ€’2mo ago
u define that in the GameManager class
Merineth πŸ‡ΈπŸ‡ͺ
is that parameter right?
TheRanger
TheRangerβ€’2mo ago
oh it was Disk, right?
Merineth πŸ‡ΈπŸ‡ͺ
yea public delegate void UpdateBoard(Disk[,] board);
TheRanger
TheRangerβ€’2mo ago
correct then in the GameGrid class you do
gameManager.OnUpdateBoard = new OnUpdateBoard(UpdateBoard);
gameManager.OnUpdateBoard = new OnUpdateBoard(UpdateBoard);
yeah rename it to OnUpdateBoard so no confusion happens with this, the delegate now points to the UpdateBoard of GameGrid so when u call it, it will call that method its pointing to
Merineth πŸ‡ΈπŸ‡ͺ
I'm not sure where in GameGrid class are you referring to?
TheRanger
TheRangerβ€’2mo ago
what do u think?
Merineth πŸ‡ΈπŸ‡ͺ
row 36?
No description
TheRanger
TheRangerβ€’2mo ago
it would be weird to register it everytime we call the GameGrid_MouseDown method we only need to register it once
Merineth πŸ‡ΈπŸ‡ͺ
I'm honestly not sure i'm not even sure what gameManager.OnUpdateBoard = new OnUpdateBoard(UpdateBoard);does
TheRanger
TheRangerβ€’2mo ago
i explained it to you, right? like twice OnUpdateBoard is a pointer you tell it which method it needs to point to so when you execute it, it will execute the method its pointing to
Merineth πŸ‡ΈπŸ‡ͺ
Ok i renamed it in GameManager
No description
TheRanger
TheRangerβ€’2mo ago
Nice
Merineth πŸ‡ΈπŸ‡ͺ
I'm still stuck at this part
TheRanger
TheRangerβ€’2mo ago
^^ think for 1 second just 1 second ull figure it out
Merineth πŸ‡ΈπŸ‡ͺ
Yeah so it shouldn't be registered in the MouseDown only when GameGrid is initialized?
TheRanger
TheRangerβ€’2mo ago
bingo
TheRanger
TheRangerβ€’2mo ago
please think for 1 second im sure the error tells u gameManager doesnt exist which actually doesnt exist
Merineth πŸ‡ΈπŸ‡ͺ
yup lol I can't change it to _gameManager
TheRanger
TheRangerβ€’2mo ago
why?
TheRanger
TheRangerβ€’2mo ago
i forgot how delegate works, lol oh yeah
public delegate void UpdateBoardDelegate(Disk[,] board);
public UpdateBoardDelegate OnUpdateBoard;
public delegate void UpdateBoardDelegate(Disk[,] board);
public UpdateBoardDelegate OnUpdateBoard;
then in GameGrid class u do
_gameManager.OnUpdateBoard = new UpdateBoardDelegate(UpdateBoard);
_gameManager.OnUpdateBoard = new UpdateBoardDelegate(UpdateBoard);
Merineth πŸ‡ΈπŸ‡ͺ
Yeah that seems to work but how can i invoke a delegate?
TheRanger
TheRangerβ€’2mo ago
invoke it like how u invoke a method OnUpdateBoard();
Merineth πŸ‡ΈπŸ‡ͺ
aaaah i see now
Merineth πŸ‡ΈπŸ‡ͺ
I changed it like this
No description
No description
Merineth πŸ‡ΈπŸ‡ͺ
would that be wrong? considering it went completely opaque I assume that when code fades out, it's not being used?
TheRanger
TheRangerβ€’2mo ago
no its not wrong but i would apply law of demeter _gameManager.DiskCount(Disk.White);
Merineth πŸ‡ΈπŸ‡ͺ
Ah ok i only have 3 errors left now From GameWindow
Merineth πŸ‡ΈπŸ‡ͺ
i assume this can be resolved like you taught me by making the if statement if(player2 is ComputerPlayer) ? actually i'm not even sure what that line fo codew deos or if it's needed
TheRanger
TheRangerβ€’2mo ago
think for 1 second what do u need this for?
Merineth πŸ‡ΈπŸ‡ͺ
It initializes the GameGrid with the isPlayer2computer flag
TheRanger
TheRangerβ€’2mo ago
does the gamegrid need that?
Merineth πŸ‡ΈπŸ‡ͺ
Not really, iirc that is determined in the new window that comes up? by clicking the computer checkmark
TheRanger
TheRangerβ€’2mo ago
better update ur github cuz idk how ur code looks like now
Merineth πŸ‡ΈπŸ‡ͺ
will do All the errors are now resolved It is however throwing an immediate exception I think it's because no instance of _gameManager has been made
TheRanger
TheRangerβ€’2mo ago
yeah
Merineth πŸ‡ΈπŸ‡ͺ
Is it possible to create an instance of something at the same time as making it a field?
TheRanger
TheRangerβ€’2mo ago
yeah
Merineth πŸ‡ΈπŸ‡ͺ
i was hoping i could do something like this but i requires player1 and player 2 i think?
Merineth πŸ‡ΈπŸ‡ͺ
because the constructor
No description
Merineth πŸ‡ΈπŸ‡ͺ
is made of it
TheRanger
TheRangerβ€’2mo ago
what if you finished the game and clicked new game again the referee will be the same, no need to get a new referee u just tell him the new players' names so i would make a method called SetPlayers in the GameManager class
Merineth πŸ‡ΈπŸ‡ͺ
I'm not sure i understand that For the game to start i need an instance of GameManager to make a new instance of gamanager i have to abide by the rules of the constructor which requires player1 and player2 or am i mistaken?
TheRanger
TheRangerβ€’2mo ago
you can define a parameterless constructor
Merineth πŸ‡ΈπŸ‡ͺ
ooooh i didn't realize i could have more than one constructor
TheRanger
TheRangerβ€’2mo ago
i need to go in few minutes
Merineth πŸ‡ΈπŸ‡ͺ
:sadge:
TheRanger
TheRangerβ€’2mo ago
what why are u creating GameManager twice
Merineth πŸ‡ΈπŸ‡ͺ
I'm just testing trying to make it so it doesn't return null throwing spaghetti trying to see if something sticks
TheRanger
TheRangerβ€’2mo ago
it will sure error when it tries to access a player variable
Merineth πŸ‡ΈπŸ‡ͺ
like so?
TheRanger
TheRangerβ€’2mo ago
it says board is null u need to create it in the constructor
Merineth πŸ‡ΈπŸ‡ͺ
oooh public GameManager() { GameManager _gamemanager = new GameManager(); }
TheRanger
TheRangerβ€’2mo ago
what are u doing lol why would the referee create another referee in himself
Merineth πŸ‡ΈπŸ‡ͺ
LMAO i'm trying my best there we gooooooo
public GameManager()
{
_board = new GameBoard();
}
public GameManager()
{
_board = new GameBoard();
}
something stuck 🍝
TheRanger
TheRangerβ€’2mo ago
remember, u can only create the gamemanager once and the board, but new players can always come
Merineth πŸ‡ΈπŸ‡ͺ
The game started without any errors but the problem is still the same
TheRanger
TheRangerβ€’2mo ago
what problem
Merineth πŸ‡ΈπŸ‡ͺ
graphical and game isn't updating
TheRanger
TheRangerβ€’2mo ago
did u update ur code to github?
Merineth πŸ‡ΈπŸ‡ͺ
yeah pushed it right now
Merineth πŸ‡ΈπŸ‡ͺ
in fact it's even worse now
TheRanger
TheRangerβ€’2mo ago
well yeah ExecuteMove returns a boolean but you never used it
Merineth πŸ‡ΈπŸ‡ͺ
Um
Merineth πŸ‡ΈπŸ‡ͺ
i pressed C4 and it removed D5
No description
Merineth πŸ‡ΈπŸ‡ͺ
it's utterly broken And i'm not sure how to use the boolean
TheRanger
TheRangerβ€’2mo ago
cuz async ur playing the game while the computer is still thinking
Merineth πŸ‡ΈπŸ‡ͺ
the ai isn't thinking at all it didn't even enter the if and execute the ai move
TheRanger
TheRangerβ€’2mo ago
if (await _gameManager.ExecuteMove(row, column))
{
}
else
{
MessageBox.Show("Invalid Move");
}
if (await _gameManager.ExecuteMove(row, column))
{
}
else
{
MessageBox.Show("Invalid Move");
}
ofcourse the computer wont think there are no players created in the gamemanager class _player2 is null
Merineth πŸ‡ΈπŸ‡ͺ
that's a lot of problems
TheRanger
TheRangerβ€’2mo ago
u totally didnt read this
Merineth πŸ‡ΈπŸ‡ͺ
I did read it i was doing something else at the time and forgot about it
TheRanger
TheRangerβ€’2mo ago
have a paper beside you and note stuff cuz missing a single note can mess up the entire program
Merineth πŸ‡ΈπŸ‡ͺ
public void SetPlayers(Player player1, Player player2)
{
_player1 = player1;
_player2 = player2;
}
public void SetPlayers(Player player1, Player player2)
{
_player1 = player1;
_player2 = player2;
}
And this method should be invoked at the start of the first game manager?
TheRanger
TheRangerβ€’2mo ago
do u know where to call this method?
Merineth πŸ‡ΈπŸ‡ͺ
My intuitive guess is the constructor
TheRanger
TheRangerβ€’2mo ago
the constructor has no parameters, so not hint : NewGameButton_Click in GameWindow.xaml.cs
Merineth πŸ‡ΈπŸ‡ͺ
does that mean the method should be located there aswell? or should it be in gamemanager and invoked in gamewindow
TheRanger
TheRangerβ€’2mo ago
invoked in gamewindow, yes GameGridControl.GameManager.SetPlayers(player1, player2);
Merineth πŸ‡ΈπŸ‡ͺ
That doesn't seem right?
TheRanger
TheRangerβ€’2mo ago
think for 1 second
Merineth πŸ‡ΈπŸ‡ͺ
i assume we are trying to invoke it on this game manager
No description
TheRanger
TheRangerβ€’2mo ago
no, our gameManager is in GameGrid, have u forgotten? u could technically make this one a getter, that gets gamemanger from gameGridControl
Merineth πŸ‡ΈπŸ‡ͺ
GameGridControl.SetPlayers(player1, player2); ?
TheRanger
TheRangerβ€’2mo ago
well sure if you want to do it this way that is professional way actually
Merineth πŸ‡ΈπŸ‡ͺ
i'm not sure what i did
Merineth πŸ‡ΈπŸ‡ͺ
but i cooked myself up 8 errors
TheRanger
TheRangerβ€’2mo ago
oh no VS thinks u defined this class twice with same fields
Merineth πŸ‡ΈπŸ‡ͺ
:Smadge:
TheRanger
TheRangerβ€’2mo ago
u sure u didnt accidentally copy this file twice?
Merineth πŸ‡ΈπŸ‡ͺ
copy file?
Merineth πŸ‡ΈπŸ‡ͺ
is it because the two constructors?
TheRanger
TheRangerβ€’2mo ago
no lets continue in another day
Merineth πŸ‡ΈπŸ‡ͺ
no problem i need a big fat break and sleep tysm for the help an actual godsent :catHeyHello: yeah that break lasted like 25 days.... and i finally found some time to try and finish this.. However the game still doesn't work properly And quite frankly i have zero idea why it's the case https://github.com/aljomatrix/Assignment2Repository
TheRanger
TheRangerβ€’3w ago
welcome back
Merineth πŸ‡ΈπŸ‡ͺ
Hiii, thanks You have no idea how glad i am to see you back
TheRanger
TheRangerβ€’3w ago
doesnt work properly how?
Merineth πŸ‡ΈπŸ‡ͺ
So i click new game input my name, sleect computer I try and place a black piece but it doesn't get placed right it did however work corretly before i tried to move everything that had with gamemanger to gamemanager
TheRanger
TheRangerβ€’3w ago
hmm is player 1 black or white?
Merineth πŸ‡ΈπŸ‡ͺ
black black always starts also so when i place C4 all white pieces between C4 and E4 should turn black
TheRanger
TheRangerβ€’3w ago
u have 2 instances of gamemanager btw
Merineth πŸ‡ΈπŸ‡ͺ
Hmm I can't even run the code anymore :/
TheRanger
TheRangerβ€’3w ago
errors i assume?
Merineth πŸ‡ΈπŸ‡ͺ
Ambiguity between 'GameGrid._gameManager' and 'GameGrid._gameManager' Yeah sadly
TheRanger
TheRangerβ€’3w ago
oh u complained about that before
Merineth πŸ‡ΈπŸ‡ͺ
Yeah i solved it with copilot lol.. but then i had some issues with the repo so i cloned it again and now copilot can't replicate the fix lol
TheRanger
TheRangerβ€’3w ago
i only see 1 GameGrid
Merineth πŸ‡ΈπŸ‡ͺ
hmm
public partial class GameGrid : UserControl
{
private GameManager _gameManager;

public void SetPlayers(Player player1, Player player2)
{
_gameManager = new GameManager(player1, player2);
}
}
}
public partial class GameGrid : UserControl
{
private GameManager _gameManager;

public void SetPlayers(Player player1, Player player2)
{
_gameManager = new GameManager(player1, player2);
}
}
}
TheRanger
TheRangerβ€’3w ago
so when u click new game, you never told the gamemanager ur starting a new game
Merineth πŸ‡ΈπŸ‡ͺ
THe issue is i can't even run the game anymore and test
No description
TheRanger
TheRangerβ€’3w ago
ambiguity, right?
Merineth πŸ‡ΈπŸ‡ͺ
Yeah
TheRanger
TheRangerβ€’3w ago
do u see anything weird in ur file explorer window in ur visual studio?
Merineth πŸ‡ΈπŸ‡ͺ
Not really i tried to restart visual studio but the error remains
TheRanger
TheRangerβ€’3w ago
did u try clicking the clean solution button? oh wait where did this come frim
Merineth πŸ‡ΈπŸ‡ͺ
GameManager.cs
TheRanger
TheRangerβ€’3w ago
No its in GameWindow.xaml.cs line 101
Merineth πŸ‡ΈπŸ‡ͺ
Oh crap sorry yes GameWindow.xaml.cs
TheRanger
TheRangerβ€’3w ago
why did you define GameGrid class again theres ur ambiguity _gameManager is defined in line 103 and in GameGrid.xaml.cs line 17 you defined the GameGrid class twice, which is fine if its partial partial means its part of that class but then you defined _gameManager again for that class
Merineth πŸ‡ΈπŸ‡ͺ
I see. So i just have to remove 101 to 109 since it's already defined? ' No nvm that doesn't seemt o be the solution
TheRanger
TheRangerβ€’3w ago
yes it is the solution u can just define the SetPlayers method at the GameGrid.xaml.cs
Merineth πŸ‡ΈπŸ‡ͺ
I'm not sure what that means
TheRanger
TheRangerβ€’3w ago
what are u confused about?
Merineth πŸ‡ΈπŸ‡ͺ
aaaaaaaaaaaaaaaa i'm gertting more errors now and i haven't done anything
TheRanger
TheRangerβ€’3w ago
what errors? did you delete the class GameGrid definition in GameWindow.xaml.cs?
Merineth πŸ‡ΈπŸ‡ͺ
I'm trying to go back
Merineth πŸ‡ΈπŸ‡ͺ
it's identical but now i got 8 errors instead of 1
TheRanger
TheRangerβ€’3w ago
the count doesnt really matter in order to fix some errors, ur bound to get more on the way whats that screenshot for? it looks like u opened the same file twice
Merineth πŸ‡ΈπŸ‡ͺ
it's guthub client so i can push and pull to repo
TheRanger
TheRangerβ€’3w ago
im aware but why are u showing me both of the same file?
Merineth πŸ‡ΈπŸ‡ͺ
I don't know, i had 1 error but now i have 8 and i didn't make any changes whatsoever i even tried copy the left side of the window but it still thinks i'm making changes which i'm not but i guess it doesn't matter as long as i have errors I tried looking up the ambig something error "You got this error because there is an ambiguity between the GameGrid._gameManager field and the GameGrid._gameManager field. This might be happening because the SetPlayers method in the GameGrid class is trying to create a new instance of GameManager instead of using the existing one." I'm not sure if it's right tho
TheRanger
TheRangerβ€’3w ago
relax, the number of errors doesnt really matter if you understand why
Merineth πŸ‡ΈπŸ‡ͺ
the issue is i have no idea 😭
TheRanger
TheRangerβ€’3w ago
its very simple u used _gameManager like 6 times in GameGrid.xaml.cs but since you defined it twice, those 6 lines doesnt know which _gameManager to use
Merineth πŸ‡ΈπŸ‡ͺ
Oh because i have two instance of _gameManager?
TheRanger
TheRangerβ€’3w ago
2 fields of _gameManager, yes for the GameGrid class
Merineth πŸ‡ΈπŸ‡ͺ
private GameManager _gameManager = new GameManager(); in GameGrid.xaml.cs is the only placse i have created _gameManager tho?
TheRanger
TheRangerβ€’3w ago
Nope
TheRanger
TheRangerβ€’3w ago
its also defined here
No description
Merineth πŸ‡ΈπŸ‡ͺ
ooh so instead of creating it there i should pass player1 and player2 and assign them instead of creating a new GameManager?
TheRanger
TheRangerβ€’3w ago
we are talking about the field bro the private GameManager _gameManager; one
Merineth πŸ‡ΈπŸ‡ͺ
that creates a new instance? oh shit you rae right i remove it and now i got 0 errors? 🧠
TheRanger
TheRangerβ€’3w ago
Nice but keep ur code clean no need to define a partial class of GameGrid in GameWindow.xaml.cs just put your SetPlayers method in the GameGrid class in GameGrid.xaml.cs
Merineth πŸ‡ΈπŸ‡ͺ
That makes sense i moved it to GameGrid.xaml.cs and still works
Merineth πŸ‡ΈπŸ‡ͺ
Now i have a completely separate issue however even clicking a position makes a runtime error
TheRanger
TheRangerβ€’3w ago
did you read the error?
Merineth πŸ‡ΈπŸ‡ͺ
Object reference not set to an instance of the object Meaning the method OnUpdateBoard(_board.BoardState); couldn't execute because it was null
TheRanger
TheRangerβ€’3w ago
yeah its null so assign it
Merineth πŸ‡ΈπŸ‡ͺ
The method or the parameters of the method?
TheRanger
TheRangerβ€’3w ago
what does the error say?
Merineth πŸ‡ΈπŸ‡ͺ
"'Object reference not set to an instance of an object"
TheRanger
TheRangerβ€’3w ago
the reason it says the reason it tells u what exactly is null
Merineth πŸ‡ΈπŸ‡ͺ
object reference should be the _board.BoardState, right?
TheRanger
TheRangerβ€’3w ago
pls read the error
Merineth πŸ‡ΈπŸ‡ͺ
I am 😭
TheRanger
TheRangerβ€’3w ago
the line under "'Object reference not set to an instance of an object" it tells you what variable is null
Merineth πŸ‡ΈπŸ‡ͺ
the object reference
TheRanger
TheRangerβ€’3w ago
bro read the line under Object reference not set to an instance of an object its right under it
Merineth πŸ‡ΈπŸ‡ͺ
ooooh OnUpdateBoard was null.
TheRanger
TheRangerβ€’3w ago
yeah
Merineth πŸ‡ΈπŸ‡ͺ
That's odd because i haven't touched OnUpdateBoard
TheRanger
TheRangerβ€’3w ago
what do you mean? was it not null before?
Merineth πŸ‡ΈπŸ‡ͺ
No, it worked fine before OnUpdateBoard seems to be a delegate at line 25 public UpdateBoardDelegate OnUpdateBoard;
TheRanger
TheRangerβ€’3w ago
yeah and its null
Merineth πŸ‡ΈπŸ‡ͺ
So i assume the delegate hasn't been assigned a method so it becomes null?
TheRanger
TheRangerβ€’3w ago
Yes
Merineth πŸ‡ΈπŸ‡ͺ
So i have to initialize it?
TheRanger
TheRangerβ€’3w ago
yes
Merineth πŸ‡ΈπŸ‡ͺ
iirc gameManager.OnUpdateBoard += SomeMethod; it's something like this? or maybe this was subscribing
TheRanger
TheRangerβ€’3w ago
yeah
Merineth πŸ‡ΈπŸ‡ͺ
OnUpdateBoard = delegate { }; i think this is how you initialize ?
TheRanger
TheRangerβ€’3w ago
look at line 24 in GameGrid.xaml.cs but i think it can be subscribed like this too
Merineth πŸ‡ΈπŸ‡ͺ
i assume gameManager.OnUpdateBoard += OnUpdateBoard; it's not something like this?
TheRanger
TheRangerβ€’3w ago
yeah subscribing it like that works
Merineth πŸ‡ΈπŸ‡ͺ
where do i want to subcribe to it like that?
No description
Merineth πŸ‡ΈπŸ‡ͺ
i tried it in GameManager but gameManager does not exist here
TheRanger
TheRangerβ€’3w ago
did u forget where _gameManager exists?
Merineth πŸ‡ΈπŸ‡ͺ
in GameGrid.Xaml.cs...
TheRanger
TheRangerβ€’3w ago
then why are u trying to use it here i feel ur just randomly putting stuff and trying ur luck
Merineth πŸ‡ΈπŸ‡ͺ
Yeah lol that's basically what i'm doing when it doesn't work
Merineth πŸ‡ΈπŸ‡ͺ
Because i tried to place it in the constructor in GameGrid.xaml.cs
TheRanger
TheRangerβ€’3w ago
do u know what a constructor does?
Merineth πŸ‡ΈπŸ‡ͺ
When we create an instance of an object it sets what is inside the constructor?
TheRanger
TheRangerβ€’3w ago
correct, its a method that gets called when u create an instance of its class so what do u understand from the pic above?
Merineth πŸ‡ΈπŸ‡ͺ
When we create the gamegrid we call the updateboard method, we create a new updateboarddelegate If i'm being completely honest the vast majority of what i learnt about c# is slowly but surely fading so it's severely difficulty for me to finish a project as hard as this. Especially when no ai tools aren't any particular help either :(
TheRanger
TheRangerβ€’3w ago
correct ofcourse ai wont help ai is just cheating ur way through
Merineth πŸ‡ΈπŸ‡ͺ
yeah the main issue is that i simply just don't have time to relearn everything from scratch again took me an entire month just to find one day off from other work to try and fix this 3 man project :( i don't even know what delegates are gameManager.OnUpdateBoard += OnUpdateBoard; I would've never figured this out on my own
TheRanger
TheRangerβ€’3w ago
a delegate is a pointer that points to a method based on the word delegate think of it as a person that does the work for another person A person authorized to act as representative for another; a deputy or agent.
Merineth πŸ‡ΈπŸ‡ͺ
What's the point of a delegate, why not just call the method directly
TheRanger
TheRangerβ€’3w ago
because the gamemanager is a backend class and cant access the GameGrid class
Merineth πŸ‡ΈπŸ‡ͺ
i see so we want to assign a method from gamemanager to that delegate so we can use it?
TheRanger
TheRangerβ€’3w ago
like how you want to send a message to ur president, u dont talk to him directly, u talk to his delegate ur restricted to see the president
Merineth πŸ‡ΈπŸ‡ͺ
By that reasoning. We want the delegate to subscribe to the method UpdateBoard in GameGrid.xaml.cs, right? So GameManager can use it?
TheRanger
TheRangerβ€’3w ago
yes, the Game Manager speaks to the delegate and asks him to update the board for him
Merineth πŸ‡ΈπŸ‡ͺ
Ok so far it makes sense how do i subscribe the delegate to it? i assume it isn't done in the constructor
TheRanger
TheRangerβ€’3w ago
constructor of what?
Merineth πŸ‡ΈπŸ‡ͺ
GameGrid I understand that i want to subscribe to the method somewhere in GameGrid.xaml.cs i'm just unsure of where
TheRanger
TheRangerβ€’3w ago
when u start the program u dont get the error right? but u get it when u click new game, correct? correct think for 1 second its in one of the methods does it make sense if you subscribe it in GameGrid_MouseDown ?
Merineth πŸ‡ΈπŸ‡ͺ
i get the error when i click on a place on the board aaaaah So since the error occurs when i click on the board i should subscrube to it on the mousedown
Merineth πŸ‡ΈπŸ‡ͺ
:/
No description
Merineth πŸ‡ΈπŸ‡ͺ
aaahj nvm should be _gameManager.. i think
TheRanger
TheRangerβ€’3w ago
thats like, u assign a new delegate that is responsible to update the board for u everytime u click on the board
Merineth πŸ‡ΈπŸ‡ͺ
that doesn't sound right
TheRanger
TheRangerβ€’3w ago
well thats what ur trying to do everytime u click the board u go hey current delegate man, ill kick u out and replace u with a new one
Merineth πŸ‡ΈπŸ‡ͺ
haha yeah i see what you mean now
TheRanger
TheRangerβ€’3w ago
so try another method, does it make sense to put it in InitializeWinnerDialog ?
Merineth πŸ‡ΈπŸ‡ͺ
No, not really
TheRanger
TheRangerβ€’3w ago
what about "InitializeBoard" ?
Merineth πŸ‡ΈπŸ‡ͺ
it does make sense in initializeboard
TheRanger
TheRangerβ€’3w ago
try and see then
Merineth πŸ‡ΈπŸ‡ͺ
Doesn't seem to be right either OnUpdateBoard isn't localy defined
TheRanger
TheRangerβ€’3w ago
what method are u trying to subscribe?
Merineth πŸ‡ΈπŸ‡ͺ
aaaah _gameManager.OnUpdateBoard += UpdateBoard; perhaps? the delegate _gameManager.OnUpdateBoard is not subscribed to UpdateBoard in GameGrid.xaml.cs that kind of makes sense i think Sadly that doesn't seem to be right tho
Merineth πŸ‡ΈπŸ‡ͺ
with the same issue/error
No description
TheRanger
TheRangerβ€’3w ago
did u put it in InitializeBoard?
Merineth πŸ‡ΈπŸ‡ͺ
Yes
TheRanger
TheRangerβ€’3w ago
it just means ur not calling the InitializeBoard method or you didnt call it
Merineth πŸ‡ΈπŸ‡ͺ
i put a breakpoint and it does call it at the start of the program
TheRanger
TheRangerβ€’3w ago
was that before u click new game or after?
Merineth πŸ‡ΈπŸ‡ͺ
the game hasn't even started yet or rather the window for it
TheRanger
TheRangerβ€’3w ago
was that before u click new game or after?
Merineth πŸ‡ΈπŸ‡ͺ
before
TheRanger
TheRangerβ€’3w ago
bingo u didnt call InitializeBoard after clicking new game
Merineth πŸ‡ΈπŸ‡ͺ
ahh i see so within the NewGameButton_Click in GameWindow.xaml.cs i haave to call it
TheRanger
TheRangerβ€’3w ago
u can call it in the SetPlayers method brb
Merineth πŸ‡ΈπŸ‡ͺ
public void SetPlayers(Player player1, Player player2)
{
InitializeBoard();
_gameManager = new GameManager(player1, player2);
}
public void SetPlayers(Player player1, Player player2)
{
InitializeBoard();
_gameManager = new GameManager(player1, player2);
}
Hmm i added the InitializeBoard(); call within the SetPlayers
No description
Merineth πŸ‡ΈπŸ‡ͺ
and got the same error oooh i made progress!! I realized InitializeBoard(); has to be after _gameManager been set up
public void SetPlayers(Player player1, Player player2)
{
_gameManager = new GameManager(player1, player2);
InitializeBoard();
}
public void SetPlayers(Player player1, Player player2)
{
_gameManager = new GameManager(player1, player2);
InitializeBoard();
}
like so!
TheRanger
TheRangerβ€’3w ago
back
Merineth πŸ‡ΈπŸ‡ͺ
welcome back! We've made progress!!! When new game is selected it does indeed make a new instance and it properly resets β™₯️ all that's left now is to make the game work properly :p
TheRanger
TheRangerβ€’3w ago
well, did u update ur git?
Merineth πŸ‡ΈπŸ‡ͺ
Yeah just pushed the changes it seems to have something to do with ExecuteMove method as far as i can tell at least I'm not entirely sure
TheRanger
TheRangerβ€’3w ago
tried debugging?
Merineth πŸ‡ΈπŸ‡ͺ
Yeah currently trying to see exactly where it happens It happens when i click on a place on the board so it's ExecuteMove Ok it happens at row 72/73 on the computerplayer if statement
TheRanger
TheRangerβ€’3w ago
before the computer plays anyway a piece gets deleted D5
Merineth πŸ‡ΈπŸ‡ͺ
Yeah it seems that way
_board.ExecuteMove(row, column, _currentPlayerDisk);
OnUpdateBoard(_board.BoardState);
TogglePlayerTurn();
_board.ExecuteMove(row, column, _currentPlayerDisk);
OnUpdateBoard(_board.BoardState);
TogglePlayerTurn();
I think it's one of these
TheRanger
TheRangerβ€’3w ago
lets solve that one first
Merineth πŸ‡ΈπŸ‡ͺ
For me it doesn't get deleted?
Merineth πŸ‡ΈπŸ‡ͺ
Here the board is exactly the same even tho line 65 and 66 have been executed
TheRanger
TheRangerβ€’3w ago
not really, the board wasnt refreshed at the breakpoint
Merineth πŸ‡ΈπŸ‡ͺ
aah so it gets removed somehwere on line 65/66 but the visual board hasn't been updated yet?
TheRanger
TheRangerβ€’3w ago
yes it called UpdateBoard, but it renders after it finishes execution
Merineth πŸ‡ΈπŸ‡ͺ
ahhh i see what u mean
TheRanger
TheRangerβ€’3w ago
it can also render during await
Merineth πŸ‡ΈπŸ‡ͺ
ahh so that's why it updates during the await when it's a computer player but renders only after the method is finished when it's PvP My bet is on OnUpdateBoard(_board.BoardState); where the problem occurs
TheRanger
TheRangerβ€’3w ago
u can just debug your BoardState
Merineth πŸ‡ΈπŸ‡ͺ
i can? would that be making a breakpoint in GameGrid.xaml.cs?
TheRanger
TheRangerβ€’3w ago
wait i think i know where the problem is can u breakpoint on UpdateBoard? i think it gets called twice lol
Merineth πŸ‡ΈπŸ‡ͺ
you mean OnUpdateBoard(_board.BoardState);?
TheRanger
TheRangerβ€’3w ago
i said UpdateBoard not OnUpdateBoard
Merineth πŸ‡ΈπŸ‡ͺ
:catsweat: UpdateBoard(_gameManager.Board.BoardState); ?
TheRanger
TheRangerβ€’3w ago
public void UpdateBoard(Disk[,] boardState)
Merineth πŸ‡ΈπŸ‡ͺ
ooh
TheRanger
TheRangerβ€’3w ago
u see i suspect something do this
public void SetPlayers(Player player1, Player player2)
{
_gameManager.OnUpdateBoard = null;
_gameManager = new GameManager(player1, player2);
InitializeBoard();
}
public void SetPlayers(Player player1, Player player2)
{
_gameManager.OnUpdateBoard = null;
_gameManager = new GameManager(player1, player2);
InitializeBoard();
}
Merineth πŸ‡ΈπŸ‡ͺ
it's setting row 3 coulmn 2 as transparant but it should be black, had to spam through the next button to get to it
No description
Merineth πŸ‡ΈπŸ‡ͺ
Hmm, i tried this and the game plays exactly the same
TheRanger
TheRangerβ€’3w ago
u added the new line?
Merineth πŸ‡ΈπŸ‡ͺ
yes
TheRanger
TheRangerβ€’3w ago
try debugging your BoardState from GameWindow.xaml.cs delete private GameManager gameManager maybe its affecting at some point
Merineth πŸ‡ΈπŸ‡ͺ
If i delete that i get 2 errors The name 'gameManager' does not exist in the current context
No description
Merineth πŸ‡ΈπŸ‡ͺ
I think it needs the field gameManager to create a new GameManager and invoke the method StartGame
TheRanger
TheRangerβ€’3w ago
why would u have 2 gamemanagers? ur gamemanager is already in GameGrid.xaml.cs
Merineth πŸ‡ΈπŸ‡ͺ
good question if i remove it
Merineth πŸ‡ΈπŸ‡ͺ
after i create a new game it becomes even worse :catsweat: when i click on C4 however
TheRanger
TheRangerβ€’3w ago
so when u click new game, the board is empty?
Merineth πŸ‡ΈπŸ‡ͺ
yeah Until i click C4 then stuff comes up but obviously completely wrong :catlaugh:
Merineth πŸ‡ΈπŸ‡ͺ
here is how it plays out
TheRanger
TheRangerβ€’3w ago
well thats normal since InitializeBoard initializes an empty board without any piece so u might want to call the updateboard method in SetPlayers
Merineth πŸ‡ΈπŸ‡ͺ
public void SetPlayers(Player player1, Player player2)
{
_gameManager.OnUpdateBoard = null;
_gameManager = new GameManager(player1, player2);
InitializeBoard();
UpdateBoard(_gameManager.Board.BoardState);
}
public void SetPlayers(Player player1, Player player2)
{
_gameManager.OnUpdateBoard = null;
_gameManager = new GameManager(player1, player2);
InitializeBoard();
UpdateBoard(_gameManager.Board.BoardState);
}
I think that's correct yeah that seems to have helped
Merineth πŸ‡ΈπŸ‡ͺ
now all that remains is to make the game work properly I went into debug mode after i clicked the c4 spot
TheRanger
TheRangerβ€’3w ago
yea u can probably see what went wrong there
Merineth πŸ‡ΈπŸ‡ͺ
it's saving my button mouse press as column 2 row 3
No description
Merineth πŸ‡ΈπŸ‡ͺ
which is c5 which is correct then it calls ExecuteMove method with that row and column
Merineth πŸ‡ΈπŸ‡ͺ
then inside the executemove method it enters the if statement which is correct since it is a correct move _board.ExecuteMove(row, column, _currentPlayerDisk); and then we enter ExecuteMove method ok i think i figured it out
Merineth πŸ‡ΈπŸ‡ͺ
the currentPlayerDisk is Empty but it should be black from the beginning of the game since black starts OMG I SOLVED IT i added
if (currentPlayerDisk == Disk.Empty)
{
currentPlayerDisk = Disk.Black;
}
if (currentPlayerDisk == Disk.Empty)
{
currentPlayerDisk = Disk.Black;
}
this if statement to the executemove so that if the executemove is called and the playerdisk is empty which indicates the start of the game it should be set to black hmmm but a new problem occurred ugh
Merineth πŸ‡ΈπŸ‡ͺ
i have literally no idea why it's doing that
Merineth πŸ‡ΈπŸ‡ͺ
it's selecting (4,2) which is C5
Merineth πŸ‡ΈπŸ‡ͺ
Ok it thinks currentPlayerDisk is Black but it's supposed to be white is it possible to set a breakpoint so i can track whenever a variable changes?
TheRanger
TheRangerβ€’3w ago
yes but what variable
Merineth πŸ‡ΈπŸ‡ͺ
currentPlyerDisk it's wrong which is causing the problem afaik it swapped or isn't swapping properly i added it to watch and trying to find the issue
TheRanger
TheRangerβ€’3w ago
well debug computers execute move
Merineth πŸ‡ΈπŸ‡ͺ
i did it.... the computer works holy shit
TheRanger
TheRangerβ€’3w ago
nice
Merineth πŸ‡ΈπŸ‡ͺ
Now i just have to fix PvP so it swaps current player disc correctly since it thinks it's always blacks turn
TheRanger
TheRangerβ€’3w ago
doesnt TogglePlayerTurn() handle that?
Merineth πŸ‡ΈπŸ‡ͺ
Yeah i just noticed that aswell
TheRanger
TheRangerβ€’3w ago
oh i see whats going on
Merineth πŸ‡ΈπŸ‡ͺ
ok i think
TheRanger
TheRangerβ€’3w ago
or not
Merineth πŸ‡ΈπŸ‡ͺ
i add another if on the toggleplayerturn to handle disk.empty quick question
public class GameManager
{
...
private Disk _currentPlayerDisk;
...
public class GameManager
{
...
private Disk _currentPlayerDisk;
...
Can i set this field to start as black? I'm a little scarred from studying vhdl where i can do := black does c# have something similar? OK i solved it it works for both now!!!!!!!!!!!!!!!!!!!!!
private Disk _currentPlayerDisk = Disk.Black;
private Disk _currentPlayerDisk = Disk.Black;
solved everything i might actually cry, you have no idea how much i appreciate your effort and willingness to help someone as hopeless as me
TheRanger
TheRangerβ€’3w ago
ur not hopeless i think u just need to learn how to study professionally
Merineth πŸ‡ΈπŸ‡ͺ
ur absolutely right
Merineth πŸ‡ΈπŸ‡ͺ
i played an entire game now but i have no more moves left but since it's my turn the winner dialogue isn't coming any idea how to track that and trigger it? Count the number of times i've pressed mousedown
TheRanger
TheRangerβ€’3w ago
noo dont do that just check if the board is full create a method called IsFull in the board class
Merineth πŸ‡ΈπŸ‡ͺ
there is a method
bool boardIsFull()
{
foreach(var cell in board)
{
if(cell == Disk.Empty)
{
return false;
}
}
return true;
}
bool boardIsFull()
{
foreach(var cell in board)
{
if(cell == Disk.Empty)
{
return false;
}
}
return true;
}
which returns a bool for it
internal bool GameOver()
{
if (boardIsFull() || (hasValidMoves(Disk.White) == false && hasValidMoves(Disk.Black) == false))
{
return true;
}
else
return false;

}
internal bool GameOver()
{
if (boardIsFull() || (hasValidMoves(Disk.White) == false && hasValidMoves(Disk.Black) == false))
{
return true;
}
else
return false;

}
TheRanger
TheRangerβ€’3w ago
nice, then use it
Merineth πŸ‡ΈπŸ‡ͺ
hmm I'm not sure where to make it i'm trying to make an if statement but
Merineth πŸ‡ΈπŸ‡ͺ
i was thinking something like this?
TheRanger
TheRangerβ€’3w ago
law of demeter maybe you should check if the board is full in the ExecuteMove method
Merineth πŸ‡ΈπŸ‡ͺ
Hmm but ExecuteMove is located in GameManager how do i invoke the InitializeWinnerDialog() from there? No wait sorry
TheRanger
TheRangerβ€’3w ago
by using Delegate
Merineth πŸ‡ΈπŸ‡ͺ
if (GameOver())
{
InitializeWinnerDialog();
}
if (GameOver())
{
InitializeWinnerDialog();
}
because currently i did it like this I'm so bad at delegates 😭 Oh wait i think i remember
TheRanger
TheRangerβ€’3w ago
just see how the OnUpdateBoard one was created
Merineth πŸ‡ΈπŸ‡ͺ
Yeahh just realized that :p
Merineth πŸ‡ΈπŸ‡ͺ
i got to a point where no more valid moves were possible by the ai so the game just stopped
TheRanger
TheRangerβ€’3w ago
nice
Merineth πŸ‡ΈπŸ‡ͺ
Well it should end the game and winner dialogoue should come up :(
TheRanger
TheRangerβ€’3w ago
well there are empty tiles u only check if the board is full
Merineth πŸ‡ΈπŸ‡ͺ
I think i have an idea I have a method called GetValidMoves which creates a list with all the valid moves do you think i can use that and check every time ExecuteMove method is called?
Merineth πŸ‡ΈπŸ‡ͺ
something like this? or what happens when a list is empty? I assume it's null?
if (Board.GetValidMoves(_currentPlayerDisk).Count == 0)
{

}
if (Board.GetValidMoves(_currentPlayerDisk).Count == 0)
{

}
maybe?
TheRanger
TheRangerβ€’3w ago
yeah
TheRanger
TheRangerβ€’3w ago
thats full tho
Merineth πŸ‡ΈπŸ‡ͺ
yeaa replaying it now to see if i get same scenario
Merineth πŸ‡ΈπŸ‡ͺ
when i click "close" i get this any ideas?
TheRanger
TheRangerβ€’3w ago
eh
Merineth πŸ‡ΈπŸ‡ͺ
it doesn't matter xd
TheRanger
TheRangerβ€’3w ago
why not just close the form with this.Close(); or something
Merineth πŸ‡ΈπŸ‡ͺ
it worked! however i had to click on a spot that's invalid for it to show but idc winnerDialog.Close(); i think that should work ok it works peeeeeeeeeeerfectly now :Ok: I can't thank you enough I'll return if my teacher has any issues tho :<
TheRanger
TheRangerβ€’3w ago
well u need to make use of the ViewModels
Merineth πŸ‡ΈπŸ‡ͺ
hey sorry didn't see u type it was only a recommendation but we'll see after my teacher has graded

Did you find this page helpful?