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
Struct, Class or Array?
-
- Posts: 190
- Joined: Sun Jul 14, 2013 10:00 am
- Real Name: H.G. Muller
Re: Struct, Class or Array?
Use arrays. Then you can index them by piece type. Says a plain-C programmer.
Re: Struct, Class or Array?
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.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
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.
"Talk is cheap. Show me the code." -- Linus Torvalds.
Re: Struct, Class or Array?
@ 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 KMA!
-
- Posts: 616
- Joined: Thu May 19, 2011 1:35 am
Re: Struct, Class or Array?
Though there is no performance difference, there is an important nuance between struct and class in C++.lucasart wrote: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.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
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.
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.