Struct, Class or Array?

Code, algorithms, languages, construction...
Post Reply
daz12
Posts: 16
Joined: Wed Feb 25, 2015 7:19 am

Struct, Class or Array?

Post by daz12 » Tue May 03, 2016 11:15 am

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

H.G.Muller
Posts: 190
Joined: Sun Jul 14, 2013 10:00 am
Real Name: H.G. Muller

Re: Struct, Class or Array?

Post by H.G.Muller » Tue May 03, 2016 2:19 pm

Use arrays. Then you can index them by piece type. Says a plain-C programmer. :lol:

lucasart
Posts: 201
Joined: Mon Dec 17, 2012 1:09 pm
Contact:

Re: Struct, Class or Array?

Post by lucasart » Sat May 14, 2016 12:36 am

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.
"Talk is cheap. Show me the code." -- Linus Torvalds.

daz12
Posts: 16
Joined: Wed Feb 25, 2015 7:19 am

Re: Struct, Class or Array?

Post by daz12 » Wed May 18, 2016 11:51 am

@ 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!

User923005
Posts: 616
Joined: Thu May 19, 2011 1:35 am

Re: Struct, Class or Array?

Post by User923005 » Tue May 24, 2016 2:48 am

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.

Post Reply