Struct, Class or Array?

Code, algorithms, languages, construction...

Struct, Class or Array?

Postby 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
daz12
 
Posts: 13
Joined: Wed Feb 25, 2015 7:19 am

Re: Struct, Class or Array?

Postby 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:
H.G.Muller
 
Posts: 179
Joined: Sun Jul 14, 2013 10:00 am

Re: Struct, Class or Array?

Postby 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.
lucasart
 
Posts: 197
Joined: Mon Dec 17, 2012 1:09 pm

Re: Struct, Class or Array?

Postby 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!
daz12
 
Posts: 13
Joined: Wed Feb 25, 2015 7:19 am

Re: Struct, Class or Array?

Postby 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.
User923005
 
Posts: 606
Joined: Thu May 19, 2011 1:35 am


Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 1 guest

cron