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
what did you do so far?
I'll share it, one moment
GitHub
GitHub - aljomatrix/Assignment2Repository
Contribute to aljomatrix/Assignment2Repository development by creating an account on GitHub.
this is the repo, i think you should have access to it
I've created the essential windows, their corresponding popups


However all that remains is the logic part
I still don't know how to set the initial board pieces for example
do u have the images of those pieces?
No. but i assume i can use some png photo online?
or just draw it on MS Paint
or you could draw ellipses
Yeah i read about the ellipses but i don't know how to make them
so i think png is easier for me?
there are tutorials on how to make ellipses in wpf


Could i use something like this perhaps?
sure
ok i have added them into my project

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
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
yeah
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?is the board form already open in the background when its asking for your name?
Yes i think so
GameWindow.xml is the first window that starts when the program starts
i assume the form on the left is the game window?
Yes
i think its fine if it asks for your names after u create the board
I think so too
The gameboard has a grid which i made

So the 4 pieces should initially go to D4, E4, D5, E5
yeah
Maybe something like this?
I assume i have to call the method in GameWindow?
sure
Having a hard time placing them tho
how so?
i think i see what u mean
I'm not familiar with how images work
u might want to create a method called CellToBoardPosition
what is the size of your image's board?
You mean the entirety of the green board?
it seems to be 400,400
correct?
Yes
if you divide 400 by 8, since there are 8 rows and 8 columns
400x400 based of the GameGrid.xaml
a cell's size is 50x50
yeah
u could start by creating that method in your board class
or CellToPixelPosition
ok
u can guess what it indicates
it obviously need parameters
Convert the picture to 50x50?
ur board is 8x8 cells, right?
yes
its purpose is to give which position in the image this cell is
I'm not sure i understand
lets grab B2
B2 is 1,1 in cell dimensions, right?
Yes
ok in image dimension, where is it?
100x100?
thats the bottom right of it
75x75
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
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
ofc u can
so ur parameters methods should be like this
u just need to do some math to convert for example 1,1 to 75,75
Oh ok
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?
Yes
My group partner who left most likely did GPT it
using GPT wont help you become a better programmer
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
tried to take C# courses online?
Yes but i don't have time
didnt they give u 6 months to make this game?
No
It's 6 months overdue
I'm already sitting 16 hours a day with other subjects
ah so the deadline was 6 months ago?
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
odd, must be a super hard uni that wants u to study 16 hours a day every day
And It's supposed to be done in groups of 3+
I mainly just need this finished
so i can continue my studies
before the deadline were you working on it?
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
so what are u going to do with this x and y?
return them i'd assume
correct
I think that's correct
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
ok
we start like this?
yeah now do u know how to add the Image to the form and set its position?
To the form? As in the grid?
as in the form
No
I don't know what a form is
the window
No i don't know how to do that
it has something to do with my URL path?
Microsoft has documentations that has a documentation on each of Image's property and methods
What?
Image Class (System.Windows.Controls)
Represents a control that displays an image.
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
this one
yeah
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
isnt it in your project folder?
new Uri("black_piece.png"); should be enough
did it find it?

the document says its UriSource not Source
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?
sure, did it work?
No

ah wops it was the bitmap image, did u try reading the link u posted? it has an example
yes but it doesn't make much sense
what do u mean?
I don't understand it
ur basically creating a new bitmap image, pointing it to its path, then attach it to the Image control
I don't know what a bitmap is and i don't know what image control is
this one might be easier
a bitmap is an image
like png, jpg
the image control is
Image piece = new Image();
the image that you will put into your boarduh
?
^
oh
using
Source
alone wont work, since you're not telling ur code which Image to apply this source toIt didn't crash
but the pieces didn't show up
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 codeI tried that earlier but
Children doesn't exist

read what i said again
oh
I don't have BoardGrid i think?
actually, your friend seems to have already initialized those :bigthonk:
which file is this?
GameWindows.xaml.cs
well its defined in the GameGrid.xaml
actually i think you should work with that file
ok
from what i see, ur friend already draw the elipses
i did it
99% of everything in the project is me
over half a year ago
i assume u used chatgpt?
yes
most likely
so technically, u did the elipse, and u dont know how it works?
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
i see, what if you made them all black, would it work?
in InitializeBoard() in GameGrid.xaml.cs
will try
yes

changing the transparant to black
it correctly fills in all the pieces on the board
then things got easier from here
i wish i checked earlier, lol
so i guess all i have to do is make them transparant again and fill in the 4 correct ones in the middle?
make it transparent again
Yeah i'm terribly sorry
Been working so long on this i completely forgot about it
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

Oh so i should seperate them?
nice but the problem is
the problem is that the
GameBoard
class does not have those pieces addedHmm
Oh i think i see what you mean
GameGrid gets them added but GameBoard in GameWindow.xaml does not?
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
Oh initialize a GameBoard
Should i keep this?
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
oh i see
so they should be linked basically?
UpdateBoard method pretty much links them
I see
add that field, to create the back end game board
oh
Ok!
...
when you define a variable in a method's scope, it means it only exists there
no any other method can access it
Makes sense
Ok so we now have an instance of GameBoard called _board
might be better to delete this
cuz u know, when you call the UpdateBoard method, it will do it for you
Oh i see
I went back tho
This is what it looks like right now
u can call UpdateBoard() after InitializeBoard();
Right
But UpdateBoard() currently expects to arguments
and do u know what argument is it?
Disk[] and Boardstate
so the boardstate, do u know where to find it?
Currently boardstate is only being used in my UpdateBoard method
but my assumption is that it's _board?
yes, its stored in _board
Hmm
UpdateBoard(_board.BoardState);
i think ?
correct, try and see
Holy
you are a genius

It did indeed update it correctly
to you maybe im a genius, but to actual seniors, no
i dont think you have implemented mouse clicks yet
No sadly not
you should start by implementing a mouseclick event for the GameGrid.xaml
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
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 casesomething in the GameBoard.cs then
I assume it's because it's not switching player in GameBoard?
debug and find out
need a small break, brb
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
cool
and i called this method inside the MouseDown event
And it does indeed work
However it's not flipping the colors of the discs
flip the colors then
in the Gameboard.cs
I think it's FlipDiskInDirection method?
Yeah i see the problem

It doesn't enter the if or else if
it went direction to else and returned void

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
need to watch how reversi works, lol
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
so basically when you click, it should find the closest black ellipse that intersects with a white ellipse?
Hmm
When i click C4
it should compare all tiles from C4 to E4
and turn them black
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
I think i did it

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

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
u could run a method in the background asynchronously
https://dotnettutorials.net/lesson/task-in-csharp/ take a look at this
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.
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

this one specifically
There is one implementation of it already tho
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
actually is threading important?
the computer can think instantly
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?
pretty much
it would be great to create a class called AI for maintability
and have multiple methods to execute in order
I see
Could i potentially rename ComputerPlayer.cs to AI.cs maybe
or do you recommend making a completely new file with AI
oh yeah i forgot it exists
π i'm so lost
what are u stuck with?
Well essentially
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)
yeah
the board should have a flag that indicates who's turn is it
Ok i think i did it
the await ExectueAIMove(); should now be what the AI should do
right?
sure
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?
ur already invoking it here
await ExecuteAIMove();
doesn't work
:(how?
what errors do u see
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
there you go
its telling you how to fix it
ooooh
It already has Task marked afaik?
internal async Task<(int x, int y)> ExecuteAIMove(GameBoard board)
its talking about the method that is calling it
the
GameGrid_MouseDown
oneOh i see
It's expecting the MouseDown method to be a Task?
yeah
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?
if its defined there then yes
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; }
public ComputerPlayer(Disk aiDisk) { _aiDisk = aiDisk; }
it tells you why
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
can u show that line

Does it have something to do with player2 being
Player
type?
Ok i think i solved it
100% pure intuitionill let you think this one ^^
Hmm ok i managed to solve all the errors
and it compiles
but i have one small question
This part here:
I just realized that unless a button is pressed it will never trigger the AI part
this part specifically
Is it possible to make it so after the human has done one turn, it will then perform that if statement?
yeah
Honestly the main problem i'm facing is
_isPlayer2Computer evaltues to false
even tho it should be true
what makes u think so? did you set it to true from anywhere?
Ah ur right
it isn't evaluated anywhere
:sadge:
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
I might lose my mind?
I added this
to my
SetupGameDialog.xaml.cs
So it indeed gets set to true
but it STILL evaluates to false
here it gets evalueted to true
u mustve set it to false at some point
what does TogglePlayerTurn() method do?
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
yea if its a property you could put a breakpoint to its setter
Ok i found out
that it changes to false
when MouseDown is triggered
but i have literally zero idea why
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
yes i know this code is a nightmare
i just want to make it work
been like an hour on this problem alone now
it will actually be more nightmare the further you go
so i advise you move them to that class,
What am i supposed to move
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
have u figured out what sets it to false?
Yes
GameGrid_MouseDown
where exactly in that method?
Whenever the button is clicked it changes to false
i put a breakpoint on the method itself
which line in the method?
Let me quadruple check, one moment
also
_isPlayer2Computer
is pointless
you dont need it
cuz you can just check if the player2
variable is an instance of ComputerPlayer
by using the is
operator, you can check if the variable can be downcasted to that class
your ComputerPlayer class extends Player, so it will definitely workBut player2 is defined in
Setupgamedialog
and i'm having the if in gamegrid
God i despise c#Player2 should be defined in the back end classes

it means its not defined
That's why i was trying to pass _isplayercomputer
where is player1 defined?
GameManager
So is player2
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?
I don't know
i have so much code i have literally no idea what i'm doing
thats what happens when you rely too much on chatgpt
It was either that or death
I mean u literally reached death by not knowing what your code does
what?
relying too much on chatgpt to do the code etc
relying
i didn't know how to do it in the firs tplace
what u need is something to have the state of your game
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.
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
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
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
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
im not here trying to bash you for using gpt but your comment there was literally what happened.
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
Anyway give me a few to look at your project and see what is usable vs what is not
Thanks
you could start by initializing HumanPlayer and ComputerPlayer instances in your GameManager class
few questions, are you suppose to use mvvm at all?
Yes, it's supposedly a requirement
ok
is there any mention on whether u can use external libraries or u have to write everything vanilla?
I'd assume vanilla
Quite frankly i don't even think they go through the code when grading
in my days they opened my code and asked me what this code and that code does π
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?
Idk what buildable means
As in, compileable?
when u right click and click build sure compileable
No
also do u have any other reqs like use Dependency Injection etc?
The requirements are like 14 pages long
oh man i wish you told me about that pdf
ok so mvvm is optional that's helpful to cut the chase
specially since most of your code is in the code behind already
it even gives you hints on how to implement stuff
yeh its very detailed
Well i'm almost done
just need the goddamn if statement tot work so my ai works
without finishing the GameManager class?
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
trust me i think its faster to finish if we finish making the GameManager class
same
so listen I see the problem you have created the players locally in your GameWindow
I trust you. But i think you severely underestimate overestimate the knowledge i have about C# and what i've learnt from class
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
no worries you will learn while we're helping you
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
Yeah i know
i gave up halfway of keeping it MVVM
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
So you want me ot implement this?


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
Becuase it's inside the if?
or rather when the new game button dissapears/closese?
you understand what a local variable is?
Yes
then explain to me
It's declared in NewGameButton so it's restricted to it?
a local variable only exists in that block, for example:
player only exists within the method Start.
Yes i know that
so you cannot access it on Stop
so none of the code in the image I posted above is usable anywhere else
So what is the solution?
No matter where i make it, it'll be restricted to where i make it
you would have a property or field to hold the GameManager and update it there
I see. So create it in GameWindow but hold it in game manager?
hint:
GameManager.Instance
might be very usefulnow 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
at the very top

but for some reason u decided to create a new local instance of the GameManager
So i could do something like this. And set them from my GameWindow?
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
π i never saw
set
being placed before get
, i guess it works lolsame hehe
i dont think they know polymorphism
So this here would be my GameWindow
And this here would be my GameManager
And this would make it so it doesn't disappear?
delete the AIPlayer2 line
Isn't it that one type can be many types?
you can basically assign an instance of ComputerPlayer to
player2
since it extends Player
classSays i can't do that

oh it doesnt extend the Player class, your pdf does say it should extend it
I don't know what extend means
derive, ComputerPlayer should be a subclass of Player
Ah
Yeah it should've been
seems that wasn't done
If i try to add that i get 100x errors

every change i make i get 100x more errors
i tried making it internal
but dthat wasn't allowed either
yeah its asking you to override the abstract method defined in the super class
those are just 6 errors not 100
funny he did HumanPlayer right
but didnt for Computer
So the problem is that i'm not implementing the request move method from player?
yeah
Don't i just add override to it?
yes, its an abstract method so u are forced to override it
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
Like so i guess
the same as HumanPlayer
I mean is it suppose to be the same? didnt u have logic for the ai
I dont know
i made it in gamegrid
the AI part is the if statement which i was trying to get to work 19:00 or so
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
I tried doing that but now i have 21 errors


no worries thats normal, it can get fixed quick
gameManager doesn't exist in gamegrid
you should know what to do, move those methods to the GameManager class
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
wait what
any window within your main window would see it
so i should move MouseDown to GameManager?
no
that is not what I said
I was referring to R
i meant the methods like TogglePlayerTurn
as for _board you would need to create its field in the GameManager class
I don't think i can move them to gamemanager
trust me bro
i'm about to pass out i'm going to take a break
i have to go very soon anyway
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
its fine we will help you move the rest properly
Unknown Userβ’2mo ago
Message Not Public
Sign In & Join Server To View
i donβt know what git checkout is
Unknown Userβ’2mo ago
Message Not Public
Sign In & Join Server To View
no
Unknown Userβ’2mo ago
Message Not Public
Sign In & Join Server To View
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...

i thoguht visual studio is free like vscode
community is free
enterprise is not
so you have to downgrade to community version
oh i must have downloaded the wrong one then

that is what u have so u probably were using a trial
instead of enterprise u want the one that says community
What is Visual Studio Copilot?
ai programmer? read about it on a reddit post last night
Unknown Userβ’2mo ago
Message Not Public
Sign In & Join Server To View
Yeah i managed to get community edition now
Unknown Userβ’2mo ago
Message Not Public
Sign In & Join Server To View
i tried copilot and it's nice that it explains the error codes i get tho

I managed to resolve all the errors present but when i run the program nothing happens now... i must have broken it completely
nothing happens like, the game window doesnt open?
Unknown Userβ’2mo ago
Message Not Public
Sign In & Join Server To View
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β’2mo ago
Message Not Public
Sign In & Join Server To View
he did share his github before
GitHub
GitHub - aljomatrix/Assignment2Repository
Contribute to aljomatrix/Assignment2Repository development by creating an account on GitHub.
The problem i'm facing is that when i click the run and debug button the program closes instantly without anything anything happening anymore
look at the bottom
failed
and errors
So me looking at this is wrong?

π

aaah okay there we go, i had to restart my visual studio for it to update
How come GameManager wont allow player2 ?

why are u accessing gameManager before creating it
well, read the error for us, and we might know why
"The name 'player2' does not exist in the current context"
it only exists in its scope, because you defined it in its scope
the variable doesnt exist anymore once it goes out of scope
Ooh right i see what you mean
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?
yes
Oufh that is tricky. Do you have any hint on how i can go about solving it?

read the error
Yeah player2 has the same problem as before
I understand that the arguments it should recieve is either ComputerPlayer2 or HumanPlayer2
why do u have multiple variables for Player2?
the player2 on the 2nd to last line will be replaced
With either
HumanPlayer2
or ComputerPlayer2
look at Player1
woops!
I see what you mean now
I managed to resolve the errors and even managed to add who player1 and player2 are which are currently playing

The only thing i'm completely clueless about tho is making the computer play if it's selected
your GameManager class seems to be useless, it doesnt do anything useful
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
Currently i tried to executeMove to 5,4 which is F5 which is a invalid move

So it throws an exception
what exception? i dont see any exception in the image
Oh sorry one moment

Is it possible to make a while loop perhaps to make it keep trying until a move is found?
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

i do have that in place for the human player
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
the list of valid moves is in fact the valid moves for black, but it should be white


omg IT WORKSSSSS
i'm literally in tears right now π
I could literally kiss you rn
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
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 :(
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
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
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
I absolutely do not have until august to finish this
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
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
they only give u the tools and knowledge to walk on your own
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
These two functions are the ones that make up my board
I'm just not entirely sure how to call the initial state (initializeboard)
I mean given how UpdateBoard works I dont think u need another method
I had a brilliant idea
just need to set the BoardState of _board
and then call UpdateBoard(_board)
Hmmm
My idea was to close the window and open a new one and passing the names put in
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
not ideal no
yeah afaik it's currently unused
should be all u need plus passing it to the updateboard
or pretty close
Oooh i think i get what you mean
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
Right i get what you mean
quick question tho
I don't want it either black, white or empty

I want it to fill the ellipse with transparant

almost like UpdateBoard does
well, fill the board with an empty disk
then tell the UI (by calling the updateBoard method)
Hi R!
(So ignoring the errors) something like this?

thats not how u call a method,
where did you define the resetboard method?
It's currently defined in GameBoard
So if i were to call UpdateBoard it'd be outside scope
and where is the UpdateBoard method defined?
UpdateBoard
is in GameGrid
ResetBoard
is in GameBoard
Maybe moving the reset method to the GameGrid would make it work?professionally the ResetBoard should be in the board class
it is recommended to encapsulate your data as much as you can
I completely forgot what encapsulate meant
google it
will do, one sec
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...
Oh so if i understand it correctly the goal is to make sure fields/attributes/methods should be under a single class?
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
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 resetu 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
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?
But the resetboard() method in Gameboard.cs doesn't reset the board afaik?
π
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
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
iβm doing the best i can π
Was that it? xD
roast me for using gpt and nothing else πΆ
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.
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
hmm lets track this, u clicked a new game, it asks for ur players names again
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
looks like u only reset the board in the UI but not in the back end
Yeah exactly, i'm not sure which instance governs that
I've tried debugging it but it's tricky
i see whats going on
You do?! :O
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
Yeah
guess what line 61 does
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?yes but, what new window?
yeah
It's the instance of SetUpGameDialog
correct, who's code is
SetupGameDialog.xaml.cs
Could it be
GameGrid gameGrid = new GameGrid();
?no
we said
SetUpGameDialog
SetUpGameDialog asks for player's namesRight
now what happens, when you click ok after u put the players' names?
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
I assigns Player1Name and the player2name. Then it creates a new instance of GameGrid and closes the window
And that's basically it?took me a while to find ur GameManager.cs, it should be in the Model folder
Yeah sorry my file management in this project is a catastrophe :catderp:
so back to the setupgamedialog
when u click ok, it closes the setupgamedialog, and returns true, right?
Yeah
so back to line 61 in GameWindow.xaml.cs, the true returned will be assigned to bool? result in line 61
Yeah that gets set to true
it initializes the player and put their names
then initializes a new GameManager in line 75
correct?
Yeah, makes sense so far!
so then, what does line 87 do?
It calls the method
which updates the board
correct
Could it be that it's passing the wrong argument?
but which board tho
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?
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
Right
yeah that makes sense based on line 22 in GameManager.cs?
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
right
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,
so the _board in gamegrid and _board in gamemanager aren't the same
they are not refering to the same board, yeah
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
No
then again ull have 2 boards, but just the 2 of them will be empty, lol
I see
new GameBoard() means u created a new board
var foo = new GameBoard(); means foo is refering to that new GameBoard()
means the 3 variables are refering to the same board
That makes sense
when u want to create a new gameboard, u should only create it once, and let 1 or more variables refer to it
I see
So we want to remove the creation of gameboard from
gamegrid
and instead reference the _board from gameboard.cs
?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
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
^ can u tell me what happened here
bar.ResetBoard(); does nothing since bar is already set to null
wrong
o.o
new GameBoard(); gets stored somewhere , lets say an invisible variable
Is it because bar doesn't update dynamically when foo changes?
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
Hmm
so foo stores a gameboard
bar becomes a copy?
that's a very tricky concept
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
ooh so
foo stores a gameboard
bar stores the reference of foo
foo gets set to null
bar.resetboard sets the gameboard to reset`?
No
foo does not store a gameboard
So we are not talking pointers from C?
it stores its refernce
if you know C, that makes it easier
yes, foo is a pointer
Right but passing a pointer you are able to change what foo is storing
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
aaaahh
that makes sense
Yeah i see what u mean
itd behave differently if GameBoard is a
struct
instead of class
but we dont have to worry about that for nowMy intuition tells me that we want to pass a reference to GameGrid?
Might be wrong tho
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
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?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 π
hahah
Well mainly get for GameGrid
:Smadge:
haha i'm so lost
what does ur pdf say?
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?
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
variableprivate GameManager _gameManager;
So i add this to the start of the GameGrid class
Does it need attributes to set ?yeah, now
are related, so better put them into the gamemanager class
_computerPlayer is useless, should be deleted
and _isPlayer2Computer useless too
But they are being used?
for my bool if statement
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 publicIf i remove those two fields i get tons of errors, i'm not sure i dare to do that
no worries we can fix it
hm ok

i guess we have to create player2 first?
we said group everything related to the game to GameManager
so the _board and _currentPlayerDisk should be moved to the GameManager class
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
what arguments are u trying to pass?
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
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
I don't know..
in my attempts to fix it i just made it worse
fml
its totally normal to make mistakes and learn from them, thats what makes us better programmers
why create _player2 when its stored in _gameManager
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
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 waywhy 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

Ok that gave me 23 errors
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
i see
in ur case these errors are easy fixable
remove public ComputerPlayer _computerPlayer
ok
remove those 2, cuz gamemanager is now responsible for them

pretend GameManager is a human that you talk to
ok
_board in gamegrid constructor also?
unneeded

unneeded as in remove it?
gameManager is already responsible for it,
yeah
roger that
what happens with updateboard since we have no _board to reference?
we do have a reference to board
that reference is stored in _gameManager
the getboard() method?
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 thatThe getter should be made in GameManager?
Yeah
public Board[,] Board => _board;
thats a getter only propertyprivate GameBoard _board { get; }
so that is wrong?u already have a field called _board tho
No i'm trying to follow ur instructions
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
i made a mistake, read this again
this is equivalent to
public GameBoard getBoard()
if you did java before
or C

i'm not sure i understand
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?
this would be my guess
but it's just a guess
voila
but it's expecting two arguments
Disk[] and boardstate
who expects 2 arguments?
nvm sorry
It's one argument disk[] boardstate
I applied the same method to the one below

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;
so how do i go about solving these

change _board from the _gamemanager?
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
i had to add.Board for it to work
you did not read my message well
read again
You mean the law of demeter?
this one

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
So i move the Isvalidmove from gameboard to gamemanager?
No
keep it
i think u cant read my messages well
basically the gamemanager's IsValidMove will call the GameBoard's IsValidMove
No i've been at this for 12+ hours i'm dizzy and it's getting hard to read
because who can only see the _currentPlayerDIsk variable? its the gamemanager
So i'm supposed to create a whole new implementation for isvalid move in the GameManager?
yeah
and it will call _board's IsValidMove
public bool IsValidMove(int row, int column)
{
return _board.IsValidMove(row, column, _board...........);
}
so like this?what is
_board...........
unfinished implementation
you should know what argument the _board's IsValidMove expects
its expecting _currentPlayerDIsk, right?
Right
so either white or black
you did move
_currentPlayerDIsk
to the GameManager class, right?no?

this is the only currentplayuerdisk i have
where is this?
from gameGrid
gamemanager should be responsible for switching turns
hes the manager after all
i have no other implementation of _currentplayerdisk
well implement one in the GameManager class then!!!!!!
he's the referee
I get that but it's not as easy as you make it sound
its definitely easy
like im super novice to c# it takess a really long time for me to understand
are u aiming to became a programmer in the future? or is this just a school project that is mandatory to do
hell no
i fucking hate c#
i'm never touching this in my life again
this is making me suicidal
which language do u prefer
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
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
it's a mandatory course in the program
i see so ur not aiming to become a programmer then
Very unlikely anymore
in GameManager class define a field
private Disk _currentPlayerDisk;
only the GameManager aka Referee can change the turns
he's responsible for switching turns
makes sense

that wasnt hard, was it?
No
the referee is the one that tells u if this cell is valid move, and he answers depending on who's turn is it
So i guess the entire if statement from GameGrid_mousedown is moved to GameManager?

since it reolves around placing pieces on the board?
i.e make a method for it?
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)
Yeah i'm trying

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
no worries
game manager is responsible for switching turns so move the toggleplayerturn to it
Hmm
I can't find my implementaiton for toggleplayerturn
we removed it
Ok i found it
That resolved one error, nice

I have no implementation of updateboard
so i guess i have to move it there?
No, we will get to that later
okie
Ok
i managed to solve

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
public async Task<bool> ExecuteMov.........
ur gonna need to return a boolean here
roger that

Seems to be proper now
honestly the computer move should be in a different method
but lets save that for later
Yeah i see what you mean
ExecuteAIMove is only defined in the ComputerPlayer class, right?
yes
Only defined in ComputerPlayer
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 memoryI see
like casting Animal to Cat
Do we ideally want to move ExecuteAIMove to GameManager so it's accessible?

think for 1 second on what to do in the first error
just think 1 second
:catlaugh:

bingo
ur laughing, are u starting to love programming?
It certainly is 10x more fun when i actually understand what i'm doing
suffering then solving problems in programming is what makes us love programming
It's like a huge pendulum swinging from suicide to ecstasy lol
yeah emotions are like a bouncing ball
if the ball falls too hard, it will bounce back higher
We are down to only 7 errors left π
Did you have a solution in mind for how to fix UpdateBoard?
delegate
like the pdf says
delegate is something like this
delegates were the #1 thing our entire class struggled with
completely incomprehensible
so one method does several things?
its a pointer
points to a method
u just tell it which method to point at
hmm
u could start by defining a field in the GameManager class
Action is syntax specific for delegates?
points at parameterless methods, yes
theres another way to define a delegate
public delegate void UpdateBoard;
right
the word
delegate
is something we went throughyeah better use that
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?public delegate void UpdateBoard(Board[,] board];
so that it can accept the UpdateBoard method with that parameter that is defined in the GameGrid clasSo i don't make a field?
u define that in the GameManager class
is that parameter right?

oh it was Disk, right?
yea
public delegate void UpdateBoard(Disk[,] board);
correct
then in the GameGrid class you do
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
I'm not sure where in GameGrid class are you referring to?
what do u think?
row 36?

it would be weird to register it everytime we call the GameGrid_MouseDown method
we only need to register it once
I'm honestly not sure
i'm not even sure what
gameManager.OnUpdateBoard = new OnUpdateBoard(UpdateBoard);
doesi 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
Ok i renamed it in GameManager

Nice

I'm still stuck at this part
^^
think for 1 second
just 1 second
ull figure it out
Yeah so it shouldn't be registered in the MouseDown
only when GameGrid is initialized?
bingo

please think for 1 second
im sure the error tells u
gameManager
doesnt exist
which actually doesnt existyup lol
I can't change it to _gameManager
why?

i forgot how delegate works, lol
oh yeah
then in GameGrid class u do
Yeah that seems to work
but how can i invoke a delegate?

invoke it like how u invoke a method
OnUpdateBoard();
aaaah i see now
I changed it like this


would that be wrong?
considering it went completely opaque
I assume that when code fades out, it's not being used?
no its not wrong
but i would apply law of demeter
_gameManager.DiskCount(Disk.White);
Ah ok
i only have 3 errors left now
From GameWindow

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
think for 1 second
what do u need this for?
It initializes the GameGrid with the isPlayer2computer flag
does the gamegrid need that?
Not really, iirc that is determined in the new window that comes up?
by clicking the computer checkmark
better update ur github cuz idk how ur code looks like now
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

yeah
Is it possible to create an instance of something at the same time as making it a field?
yeah

i was hoping i could do something like this
but i requires player1 and player 2 i think?
because the constructor

is made of it
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
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?
you can define a parameterless constructor
ooooh
i didn't realize i could have more than one constructor
i need to go in few minutes
:sadge:

what why are u creating GameManager twice
I'm just testing
trying to make it so it doesn't return null
throwing spaghetti trying to see if something sticks
it will sure error when it tries to access a player variable

like so?
it says board is null
u need to create it in the constructor
oooh
public GameManager()
{
GameManager _gamemanager = new GameManager();
}
what are u doing lol
why would the referee create another referee in himself
LMAO i'm trying my best
there we gooooooo
something stuck π
remember, u can only create the gamemanager once and the board, but new players can always come
The game started without any errors
but the problem is still the same
what problem
graphical and game isn't updating
did u update ur code to github?
yeah pushed it right now
in fact it's even worse now
well yeah
ExecuteMove returns a boolean
but you never used it
Um
i pressed C4 and it removed D5

it's utterly broken
And i'm not sure how to use the boolean
cuz async
ur playing the game while the computer is still thinking
the ai isn't thinking at all
it didn't even enter the if and execute the ai move
ofcourse the computer wont think
there are no players created in the gamemanager class
_player2 is null
that's a lot
of problems
u totally didnt read this
I did read it
i was doing something else at the time and forgot about it
have a paper beside you and note stuff
cuz missing a single note can mess up the entire program
And this method should be invoked at the start of the first game manager?
do u know where to call this method?
My intuitive guess is the constructor
the constructor has no parameters, so not
hint : NewGameButton_Click in GameWindow.xaml.cs
does that mean the method should be located there aswell?
or should it be in gamemanager and invoked in gamewindow
invoked in gamewindow, yes
GameGridControl.GameManager.SetPlayers(player1, player2);
That doesn't seem right?

think for 1 second
i assume we are trying to invoke it on this game manager

no, our gameManager is in GameGrid, have u forgotten?
u could technically make this one a getter, that gets gamemanger from gameGridControl
GameGridControl.SetPlayers(player1, player2);
?well sure if you want to do it this way
that is professional way actually
i'm not sure what i did

but i cooked myself up 8 errors
oh no
VS thinks u defined this class twice
with same fields
:Smadge:
u sure u didnt accidentally copy this file twice?
copy file?

is it because the two constructors?
no
lets continue in another day
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
welcome back
Hiii, thanks
You have no idea how glad i am to see you back
doesnt work properly how?

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
hmm
is player 1 black or white?
black
black always starts also
so when i place C4
all white pieces between C4 and E4 should turn black
u have 2 instances of gamemanager btw
Hmm
I can't even run the code anymore :/
errors i assume?
Ambiguity between 'GameGrid._gameManager' and 'GameGrid._gameManager'
Yeah sadly
oh u complained about that before
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
i only see 1 GameGrid
hmm
so when u click new game, you never told the gamemanager ur starting a new game
THe issue is i can't even run the game anymore and test

ambiguity, right?
Yeah
do u see anything weird in ur file explorer window in ur visual studio?
Not really
i tried to restart visual studio
but the error remains
did u try clicking the clean solution button?
oh wait
where did this come frim
GameManager.cs
No
its in GameWindow.xaml.cs
line 101
Oh crap sorry
yes GameWindow.xaml.cs
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
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
yes it is the solution
u can just define the SetPlayers method at the GameGrid.xaml.cs
I'm not sure what that means
what are u confused about?
aaaaaaaaaaaaaaaa
i'm gertting more errors now
and i haven't done anything
what errors?
did you delete the class GameGrid definition in GameWindow.xaml.cs?
I'm trying to go back

it's identical
but now i got 8 errors
instead of 1

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
it's guthub client
so i can push and pull to repo
im aware but why are u showing me both of the same file?
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
relax, the number of errors doesnt really matter
if you understand why
the issue is i have no idea π
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
Oh because i have two instance of _gameManager?
2 fields of _gameManager, yes
for the GameGrid class
private GameManager _gameManager = new GameManager();
in GameGrid.xaml.cs is the only placse i have created _gameManager tho?Nope
its also defined here

ooh
so instead of creating it there
i should pass player1 and player2 and assign them
instead of creating a new GameManager?
we are talking about the field bro
the
private GameManager _gameManager;
onethat creates a new instance?
oh shit you rae right
i remove it and now i got 0 errors?
π§
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
That makes sense
i moved it to GameGrid.xaml.cs and still works

Now i have a completely separate issue however
even clicking a position makes a runtime error
did you read the error?
Object reference not set to an instance of the object
Meaning the method
OnUpdateBoard(_board.BoardState);
couldn't execute because it was nullyeah
its null
so assign it
The method or the parameters of the method?
what does the error say?
"'Object reference not set to an instance of an object"
the reason
it says the reason
it tells u what exactly is null
object reference should be the _board.BoardState, right?
pls read the error
I am π
the line under
"'Object reference not set to an instance of an object"
it tells you what variable is nullthe object reference
bro
read the line under
Object reference not set to an instance of an object
its right under itooooh
OnUpdateBoard was null.
yeah
That's odd because i haven't touched OnUpdateBoard
what do you mean?
was it not null before?
No, it worked fine before
OnUpdateBoard seems to be a delegate
at line 25
public UpdateBoardDelegate OnUpdateBoard;
yeah
and its null
So i assume the delegate hasn't been assigned a method so it becomes null?
Yes
So i have to initialize it?
yes
iirc
gameManager.OnUpdateBoard += SomeMethod;
it's something like this?
or maybe this was subscribingyeah
OnUpdateBoard = delegate { };
i think this is how you initialize ?look at line 24 in GameGrid.xaml.cs
but i think it can be subscribed like this too
i assume
gameManager.OnUpdateBoard += OnUpdateBoard;
it's not something like this?yeah subscribing it like that works
where do i want to subcribe to it like that?

i tried it in GameManager but gameManager does not exist here
did u forget where _gameManager exists?
in GameGrid.Xaml.cs...
then why are u trying to use it here
i feel ur just randomly putting stuff and trying ur luck
Yeah lol that's basically what i'm doing when it doesn't work

Because i tried to place it in the constructor
in GameGrid.xaml.cs
do u know what a constructor does?
When we create an instance of an object it sets what is inside the constructor?
correct, its a method that gets called when u create an instance of its class
so what do u understand from the pic above?
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 :(
correct
ofcourse ai wont help
ai is just cheating ur way through
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 owna 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.
What's the point of a delegate, why not just call the method directly
because the gamemanager is a backend class and cant access the GameGrid class
i see
so we want to assign a method from gamemanager
to that delegate
so we can use it?
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
By that reasoning. We want the delegate to subscribe to the method UpdateBoard in GameGrid.xaml.cs, right?
So GameManager can use it?
yes, the Game Manager speaks to the delegate and asks him to update the board for him
Ok so far it makes sense
how do i subscribe the delegate to it?
i assume it isn't done in the constructor
constructor of what?
GameGrid
I understand that i want to subscribe to the method
somewhere in GameGrid.xaml.cs
i'm just unsure of where
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 ?
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
:/

aaahj
nvm
should be _gameManager.. i think
thats like, u assign a new delegate that is responsible to update the board for u everytime u click on the board
that doesn't sound right
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
haha
yeah i see what you mean now
so try another method, does it make sense to put it in
InitializeWinnerDialog
?No, not really
what about "InitializeBoard" ?
it does make sense in initializeboard
try and see then

Doesn't seem to be right either
OnUpdateBoard isn't localy defined
what method are u trying to subscribe?
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 thowith the same issue/error

did u put it in InitializeBoard?
Yes

it just means ur not calling the InitializeBoard method
or you didnt call it

i put a breakpoint and it does call it at the start of the program
was that before u click new game or after?
the game hasn't even started yet
or rather the window for it
was that before u click new game or after?
before
bingo
u didnt call InitializeBoard after clicking new game
ahh i see
so within the
NewGameButton_Click
in GameWindow.xaml.cs i haave to call itu can call it in the SetPlayers method
brb
Hmm i added the InitializeBoard(); call within the SetPlayers

and got the same error
oooh i made progress!!
I realized InitializeBoard(); has to be after _gameManager been set up
like so!
back
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

well, did u update ur git?
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
tried debugging?
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
before the computer plays anyway a piece gets deleted
D5
Yeah it seems that way
I think it's one of these
lets solve that one first
For me it doesn't get deleted?

Here the board is exactly the same
even tho line 65 and 66 have been executed
not really,
the board wasnt refreshed
at the breakpoint
aah so it gets removed somehwere on line 65/66 but the visual board hasn't been updated yet?
yes it called UpdateBoard, but it renders after it finishes execution
ahhh i see what u mean
it can also render during await
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
u can just debug your BoardState
i can?
would that be making a breakpoint in GameGrid.xaml.cs?
wait i think i know where the problem is
can u breakpoint on UpdateBoard?
i think it gets called twice lol
you mean
OnUpdateBoard(_board.BoardState);
?i said UpdateBoard not OnUpdateBoard
:catsweat:
UpdateBoard(_gameManager.Board.BoardState); ?
public void UpdateBoard(Disk[,] boardState)
ooh
u see i suspect something
do this
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

Hmm, i tried this and the game plays exactly the same
u added the new line?

yes

try debugging your BoardState
from GameWindow.xaml.cs delete
private GameManager gameManager
maybe its affecting at some pointIf i delete that i get 2 errors
The name 'gameManager' does not exist in the current context

I think it needs the field gameManager to create a new GameManager and invoke the method StartGame
why would u have 2 gamemanagers?
ur gamemanager is already in GameGrid.xaml.cs
good question
if i remove it

after i create a new game it becomes even worse
:catsweat:
when i click on C4 however


so when u click new game, the board is empty?
yeah
Until i click C4 then stuff comes up
but obviously completely wrong :catlaugh:

here is how it plays out
well thats normal since InitializeBoard initializes an empty board without any piece
so u might want to call the updateboard method
in SetPlayers
I think that's correct
yeah that seems to have helped

now all that remains is to make the game work properly
I went into debug mode
after i clicked the c4 spot
yea u can probably see what went wrong there
it's saving my button mouse press as column 2 row 3

which is c5
which is correct
then it calls ExecuteMove method with that row and column

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
the currentPlayerDisk is
Empty
but it should be black
from the beginning of the game since black starts
OMG
I SOLVED IT
i added
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
i have literally no idea why it's doing that

it's selecting (4,2) which is C5

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?
yes but what variable
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 issuewell debug computers execute move
i did it....
the computer works
holy shit
nice
Now i just have to fix PvP
so it swaps current player disc correctly
since it thinks it's always blacks turn
doesnt TogglePlayerTurn() handle that?
Yeah
i just
noticed that aswell
oh i see whats going on
ok i think
or not
i add another if on the toggleplayerturn
to handle
disk.empty
quick question
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!!!!!!!!!!!!!!!!!!!!!
solved everything
i might actually cry, you have no idea how much i appreciate your effort and willingness to help someone as hopeless as meur not hopeless i think u just need to learn how to study professionally
ur absolutely right

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
noo dont do that
just check if the board is full
create a method called IsFull in the board class
there is a method
which returns a bool for it
nice, then use it
hmm
I'm not sure where to make it
i'm trying to make an if statement but

i was thinking something like this?
law of demeter
maybe you should check if the board is full in the ExecuteMove method
Hmm but ExecuteMove is located in GameManager
how do i invoke the InitializeWinnerDialog() from there?
No wait sorry
by using Delegate
because currently i did it like this
I'm so bad at delegates π
Oh wait i think i remember
just see how the OnUpdateBoard one was created
Yeahh just realized that :p

i got to a point where
no more valid moves were possible by the ai
so the game just stopped
nice
Well it should end the game and winner dialogoue should come up
:(
well there are empty tiles
u only check if the board is full
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?

something like this?
or what happens when a list is empty?
I assume it's null?
maybe?
yeah

thats full tho
yeaa
replaying it now
to see if i get same scenario

when i click "close"
i get this
any ideas?
eh
it doesn't matter xd
why not just close the form
with
this.Close();
or something
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 :<
well u need to make use of the ViewModels
hey sorry didn't see u type
it was only a recommendation but we'll see after my teacher has graded