[Jprogramming] chess pieces

Oleg Kobchenko olegykj at yahoo.com
Wed Sep 10 08:21:08 HKT 2008


You load the chess32.bmp and cut into a list of piece icons.
It should be indexed by piece, color and square color.
Makes sense to superimpose checkered board on pieces.

Then you assemble the 8x8 board of those indices
replacing with icons and stitch it.




> From: Björn Helgason <gosinn at gmail.com>
> To: Programming forum <programming at jsoftware.com>
> Sent: Tuesday, September 9, 2008 7:56:02 PM
> Subject: [Jprogramming] chess pieces
> 
> I have been meaning to try out the chess pieces for a long time but never
> got around to it until now.
> 
> http://www.jsoftware.com/jwiki/Scripts/Chess_Generator
> I took the cardgen script and used it as a starting point as suggested and
> tested until I got the chesspieces displayed correctly.
> 
> require 'viewmat'
> 
> F=: readbmp jpath'~user/chess/chess32.bmp'
> C=: ,/}:"_1 ] 0 1 2 3 4{(,:~32 31) ];.3 F
> T=: 16ba000
> 
>     maxd =: |:@:({.@$&>) {@;&(>./) {:@$&>
>    table  =: [: > [: ,&.>/ [: ,.&.>/"1 maxd {.!.T&.> ]
>     hand =: (,!.T)&.>/
> NB.   stack=: (,.~ 12&{."1)~/
>     stack=: (,.~ 1&{."1)~/
> NB.   group=: [: (<.@%&13 >     group=: [: (<.@%&1 >    shand  =: empty`([: >@hand (~ group)@.(*@#)
> 
> NB.   tabmat =: 3 3 $&, a:&,.
> tabmat =: 8 16 $&, a:&,.
> view     =: [:viewrgb [:table [:shand&.> tabmat
> deal     =: _2(<\?~)30"_
> 
> NB.  view deal''
> a=:
> 9;19;8;22;11;20;7;21;18;6;18;6;18;6;18;6;24;25;24;25;24;25;24;25;25;24;25;24;25;24;25;24;24;25;24;25;24;25;24;25;25;24;25;24;25;24;25;24;0;12;0;12;0;12;0;12;15;1;14;4;17;2;13;3
> b=:
> 9;19;8;22;11;20;7;21;18;6;18;6;18;6;18;6;24;25;24;25;24;25;24;25;25;24;25;24;25;24;25;24;24;25;24;25;24;25;24;25;25;24;25;24;25;24;25;24;0;12;0;12;0;12;0;12;15;1
> 1;14;4;17;2;13;3
> view a
> view b
> 
> ---------------------------------------
> 
> view a gives me a wrong piece
> It gives pawn instead of the knight
> (piece 0 instead of piece 1)
> 
> view b gives the knight in the right place but a green line down the table
> (used 1 1 instead of 1)
> 
> I am pretty sure this is not the best solution but it sort of works.
> 
> Can someone please explain why view a displays the wrong piece?


      


More information about the Programming mailing list