Differences between revisions 1 and 2
Revision 1 as of 2008-12-26 15:11:32
Size: 3465
Editor: anonymous
Comment:
Revision 2 as of 2008-12-26 15:23:36
Size: 4149
Editor: anonymous
Comment: New page - under construction
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
Having read the Solitaire article by StephenTaylor I thought I would set out a series of functions which use the creation of playing cards to demonstrate APl's ability to use data stored in third party resources, native files and the workspace and to manipulate the data using boolean patterns. Having read the SolitaireGame article by StephenTaylor I thought I would set out a series of functions which use the creation of playing cards to demonstrate APL's ability to use data stored in third party resources, native files and the workspace and to manipulate the data using boolean patterns. APL is particularly good at exploiting data patterns.

The functions are written in APL+WIN but they should be readily convertible into any GUI enabled interpreter as they only use a simple form and a picture control for the graphics and
⎕wcall for making low level windows calls.

The main function Solitaire creates a graphical card table complete with the initial deal. The functions that follow implement the data handling involved and can be used to create any card game. More importantly they demonstrate some of APL's data handling capabilities. I have deliberately written the functions in what I call "long hand APL" so that they are easy to read and understand.

Playing Cards - Under Construction

Having read the SolitaireGame article by StephenTaylor I thought I would set out a series of functions which use the creation of playing cards to demonstrate APL's ability to use data stored in third party resources, native files and the workspace and to manipulate the data using boolean patterns. APL is particularly good at exploiting data patterns.

The functions are written in APL+WIN but they should be readily convertible into any GUI enabled interpreter as they only use a simple form and a picture control for the graphics and ⎕wcall for making low level windows calls.

The main function Solitaire creates a graphical card table complete with the initial deal. The functions that follow implement the data handling involved and can be used to create any card game. More importantly they demonstrate some of APL's data handling capabilities. I have deliberately written the functions in what I call "long hand APL" so that they are easy to read and understand.

 ∇  Solitaire;i;j;cbk;n;bkg;ep;c                               
                                                           
⍝Display Card Table                                        
CardTable                                                  
'fm' ⎕wi 'caption' 'Solitaire'                             
                                                           
⍝Get the card back bitmap                                  
cbk←MakeCardDLL 62                                         
                                                           
⍝Get the empty pile bitmap                                 
ep←MakeCardDLL 53                                          
                                                           
⍝Select 8 cards at random                                  
c←10?52                                                    
                                                           
⍝Display discard piles                                     
:for i :in ⍳4                                              
    bkg←(∼∆bkg)×⎕wi 'Get' 7 (180+86×i) 96 71               
    ⎕wi 'Put' (bkg+∆bkg×(1↑,bkg)×∼ep=0) 7 (180+86×i)       
:endfor                                                    
                                                           
⍝Display draw pile                                         
:for i :in ⍳3                                              
    bkg←(∼∆bkg)×⎕wi 'Get' (5+2×i) (5+2×i) 96 71            
    ⎕wi 'Put' (bkg+cbk) (5+2×i) (5+2×i)                    
:endfor                                                    
                                                           
⍝Display first three cards drawn                           
:for i :in ⍳3                                              
    bkg←(∼∆bkg)×⎕wi 'Get' (7+2×i) (80+15×i) 96 71          
    ⎕wi 'Put' (bkg+MakeCardDLL c[i]) (7+2×i) (80+15×i)     
:endfor                                                    
                                                           
⍝Display the seven initial deal piles                      
:for i :in ⍳7                                              
                                                           
⍝Face down cards                                           
    :for j :in ⍳i-1                                        
        bkg←(∼∆bkg)×⎕wi 'Get'(130+3×j) (7+86×i-1) 96 71    
        ⎕wi 'Put' (bkg+cbk) (130+3×j) (7+86×i-1)           
    :endfor                                                
                                                           
⍝Face up cards                                             
    bkg←(∼∆bkg)×⎕wi 'Get' (130+3×i) (7+86×i-1) 96 71       
    ⎕wi 'Put' (bkg+MakeCardDLL c[i+3]) (130+3×i) (7+86×i-1)
:endfor                                                    
                                                           
'fm' ⎕wi 'visible' 1                           
                                                                

PlayingCards (last edited 2012-02-18 15:11:38 by KaiJaeger)