how to take one bool in a large C# set, and compare it to the rest of the set to know if a duplicate result pops up?

1    01 Mar 2019 05:59 by u/theoldones

ive got a large bool set right now that tracks whether or not a specific square on a chessboard is occupied or not, but i need to know how to make one code check to sift through the rest of the set in one go, to know whether or not a given square is cleared or not

7 comments

0

Okay, I'll bite. A set is just a collection of things, wouldn't you want an 8 x 8 array of booleans to keep track of which squares are occupied, true or false.

0

i have:

-2 variable sets tracking each board axis with bools

-the board has a cursor that tracks its location and uses the previous to get a location

-each piece has it's current axis stored with an integer in 2 other sets

-various script modules for placing pieces, can check to see if the square is occupied, but not by what

somehow i need to go from:

cursor location --> check to see what occupies this spot --> get an integer that tells the system the piece

0

I don't understand that first thing "2 variable sets tracking each board axis with bools". Sets are good for keeping track of unordered collections of stuff, like a set of active white pieces, or another of captured black pieces, or whatever. For something like the board you know there are exactly 64 squares or 8x8 so build a two dimenstional array of squares.

The Cursor is used for considering potential moves?

The whole big deal about an object oriented approach is you try to model the real world. So make a Square object and have an 8x8 array of them. The Square object holds whatever is of interest about chess squares. It can have a Piece or null for empty. Pieces are Black or White, Live or Captured. A Rook is a specialized kind of Piece. Now you can move the Cursor according to Rook movement and for each position x, y just look up the Square directly and see what's happening on that Square.

0

the cursor is moved with keys, and is a cursor. move consideration is one use for it, yes

i'll try adding another dimension here and looking at the right coordinates then

is there a way to overwrite everything to null, for when i clean and reset the board?

0

Okay I get the Cursor better now.

You could have a Board object that has the Square[8][8] array and creates each Square with appropriate checkerboard colors in the constructor. It could have a reset method that loops through and sets all Square.Piece to null, called from the constructor and whenever you clean and reset.

Board could create all of the Pieces too. That reset method could position them on the Squares and put all of them in the Active Set and clear the Captured Set. Something like that.

Don't forget a method to knock the board over, j/k.

0

Just represent your board as a single array where each position is either 1 or 0 and then XOR it against an array of the same dimension that is all 0's.

0 XOR 0 = 0 1 XOR 1 = 0 1 XOR 0 = 1 0 XOR 1 = 1

0

External links often go to Wikipedia or Google Groups.

https://www.chessprogramming.org/Board_Representation https://www.chessprogramming.org/Move_Generation https://www.chessprogramming.org/Check

For C# syntax and/or idioms?

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/foreach-in https://stackoverflow.com/questions/183685/c-sharp-set-collection https://answers.unity.com/questions/1138410/how-do-i-check-if-all-booleans-in-an-array-are-fal.html

I just saw your other reply, can you use enums instead of booleans? It would mean comparing against piece_empty instead of false. It might involve editing several places in code depending how it was written so far...