Page 1 of 1

Chess board

Posted: Fri Oct 06, 2023 4:44 pm
by Olli
Small code to display a chess board. Open bar to the cheat !
:mrgreen:
If display problem, please tell me the OS version.

Code: Select all

h = 3 * DesktopHeight(winB + ExamineDesktops() * 0) / 4
winB = OpenWindow(#PB_Any, 0, 0, h, h, "Chess board", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
hb = h / 8
SetGadgetFont(#PB_Default, FontID(LoadFont(#PB_Any, "courier", hb / 2) ) )
For i = 0 To 63
    x = i & 7
    y = (i & 56) >> 3
    StringGadget(i, x * hb, y * hb, hb, hb, Chr(32 + (9779 + ((($76232B >> (3 * x) & 7) * Bool(Not(y) Or Not(y - 7) ) ) | (Bool(Not(y - 1) Or Not(y - 6) ) * 6) ) ) * Bool((((y >> 2) ! (y >> 1)) & 1) ! 1) ) )
    SetGadgetColor(i, #PB_Gadget_BackColor, RGB(108, 128, 108) + ((x & 1) ! (y & 1) ) * RGB(147, 64, 20) )
    SetGadgetColor(i, #PB_Gadget_FrontColor, RGB(255, 255, 255) * Bool(y & 4) )
Next
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: Chess board

Posted: Sat Oct 07, 2023 1:42 am
by BarryG
Olli wrote:StringGadget(i, x * hb, y * hb, hb, hb, Chr(32 + (9779 + ((($76232B >> (3 * x) & 7) * Bool(Not(y) Or Not(y - 7) ) ) | (Bool(Not(y - 1) Or Not(y - 6) ) * 6) ) ) * Bool((((y >> 2) ! (y >> 1)) & 1) ! 1) ) )
I'll never understand how that works (and I don't want to know). Just amazing. You have a good brain!

Re: Chess board

Posted: Mon Oct 09, 2023 5:54 pm
by dige
This makes me crazy! :shock: great small code!

Re: Chess board

Posted: Mon Oct 09, 2023 8:57 pm
by jacdelad
@Olli, this is cool!
How about using a TextGadget, or do you want the StringGadget to be able to move the pieces by hand?

Code: Select all

h = 3 * DesktopHeight(winB + ExamineDesktops() * 0) / 4
winB = OpenWindow(#PB_Any, 0, 0, h, h, "Chess board", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
hb = h / 8
SetGadgetFont(#PB_Default, FontID(LoadFont(#PB_Any, "courier", hb / 1.5) ) )
For i = 0 To 63
    x = i & 7
    y = (i & 56) >> 3
    TextGadget(i, x * hb, y * hb, hb, hb, Chr(32 + (9779 + ((($76232B >> (3 * x) & 7) * Bool(Not(Mod(y,7) ) ) ) | (Bool(Not(Mod(y-1,5) ) ) * 6) ) ) * Bool((((y >> 2) ! (y >> 1)) & 1) ! 1) ), #PB_Text_Center)
    SetGadgetColor(i, #PB_Gadget_BackColor, RGB(108, 128, 108) + ((x & 1) ! (y & 1) ) * RGB(147, 64, 20) )
    SetGadgetColor(i, #PB_Gadget_FrontColor, RGB(255, 255, 255) * Bool(y & 4) )
Next
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
BTW, you can save some more chars in your monster formula by using mod two times.

Re: Chess board

Posted: Mon Oct 09, 2023 10:41 pm
by Olli
1) I apologize for the formula : I will simplify.
2) I use StringGadget as a good personnal choice.

I find this gadget is well adapted to this game (excepted for XP and older)

And I wanted the "ergonomy" part stays short to be concentrated for the game, and to allow everybody to code what we want then.

Re: Chess board

Posted: Thu Oct 12, 2023 8:03 pm
by Kwai chang caine
Incredible , you never finish to etonashing me :shock:
Thanks for sharing this little jewel
BarryG wrote:You have a good brain!
It's not the first time i think the same thing 8)