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.
377 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β’2d ago
Message Not Public
Sign In & Join Server To View
i donβt know what git checkout is
Unknown Userβ’2d ago
Message Not Public
Sign In & Join Server To View
no
Unknown Userβ’2d ago
Message Not Public
Sign In & Join Server To View