Page 1 of 1

Struct, Class or Array?

Posted: Tue May 03, 2016 11:15 am
by daz12
I'm going with a bitboard representation but not sure if bitboards and other info about board should sit within a class, struct or simply an array. If I keep creating class instances I understand that might slow the program down. I could use a struct but there seems to be advice that says info in a struct should be immutable. If I go with static class then I can't copy state for searching in a search algorithm but it has performance benefit. Any advice on this would be appreciated. :|

Thanks

Daz

Re: Struct, Class or Array?

Posted: Tue May 03, 2016 2:19 pm
by H.G.Muller
Use arrays. Then you can index them by piece type. Says a plain-C programmer. :lol:

Re: Struct, Class or Array?

Posted: Sat May 14, 2016 12:36 am
by lucasart
daz12 wrote:I'm going with a bitboard representation but not sure if bitboards and other info about board should sit within a class, struct or simply an array. If I keep creating class instances I understand that might slow the program down. I could use a struct but there seems to be advice that says info in a struct should be immutable. If I go with static class then I can't copy state for searching in a search algorithm but it has performance benefit. Any advice on this would be appreciated. :|

Thanks

Daz
I think you need to start by Programming 101. At this point, it's obvious that writing a chess engine is way beyond your skills.

PS: struct and class are the same thing in C++. there is no difference in performance (and indeed compiled code) if you put an array in a struct/class.

Re: Struct, Class or Array?

Posted: Wed May 18, 2016 11:51 am
by daz12
@ lucasart for your information I've made quite a lot of progress and managed to do things I didn't think I could, so I won't let your opinion limit my ambitions :twisted: KMA!

Re: Struct, Class or Array?

Posted: Tue May 24, 2016 2:48 am
by User923005
lucasart wrote:
daz12 wrote:I'm going with a bitboard representation but not sure if bitboards and other info about board should sit within a class, struct or simply an array. If I keep creating class instances I understand that might slow the program down. I could use a struct but there seems to be advice that says info in a struct should be immutable. If I go with static class then I can't copy state for searching in a search algorithm but it has performance benefit. Any advice on this would be appreciated. :|

Thanks

Daz
I think you need to start by Programming 101. At this point, it's obvious that writing a chess engine is way beyond your skills.

PS: struct and class are the same thing in C++. there is no difference in performance (and indeed compiled code) if you put an array in a struct/class.
Though there is no performance difference, there is an important nuance between struct and class in C++.
A struct has data members and methods that are public by default and a class has private access by default.
I am sure that Lucas knows this but the O.P. may not.