English 

Pagine web di Gianni Ciolli

url: http://web.math.unifi.it/users/ciolli/dama.html | Home page


Giocate a dama?

allora potete fare uso del seguente codice Java, realizzato dal mio amico G.

class Sc extends javax.swing.JButton {
    static javax.swing.JFrame f = new javax.swing.JFrame();
    static Sc o[]=new Sc[64], p[]=new Sc[100], c, r=new Sc(), A,B,D;
    int i,j,s,x,   n,   h, e, d, g, w, q, t,       K,F,L,U=1,M;
    public void paintComponent( java.awt.Graphics g ) {
        super.paintComponent((x=(A=this)==A&E(0)>-1&(r.q+=r.M)>-1&x>0&r.F>0?s=0:0)<1? g:g);
        g.setColor(new java.awt.Color(s<2?16777196:s==2?0:s==3?8388607:180<<16));
        g.fillOval(8,8, s!=0? getWidth()-16: -1, s!=0? getHeight()-16: -1);
    }
    int E( int a ) {
        for(int k= a<2? r.M=0 : 64; k<64; B=o[k++], r.M+=E(a+2)==0? 1:0 );
        if(a<8 && (h=a>1 && s%2==r.U & (g=B.j-A.j)*g==(d=B.i-A.i)*d & d*d==4?2:1)>0 )
            return (B.s<1|B==this) & (s>2|d==6-4*s) & (D=o[(A.i+B.i)/2+(A.j+B.j)*4]).s!=0
                & h>1 & x<1 & (s>2||D.s<3) & D.s%2!=r.U & D.x<1 && (D.x=a%2)>-1? 0:1;  
        for( K=L-1, A=c=p[e=h=0]; h<K; B=p[h+1], e+=c.E(3), ++h, A=B );
        F=(K>0 & (t=c.s)!=0 & ((K==1 & q<1 & p[1].s<1 & (w=p[1].j-c.j)*w==1 & t%2==U
            & (w=p[1].i-c.i)*w==1 & (2*U-1==w|t>2)) | (e<1&c.E(0)>=0&M<1)) )? 1:0;
        return q=L=F>0?(c.s=0)*(U=++U%2)*(p[K].s=t+(p[K].i==(6+t)%8+t/3*8?2:0)):0;
    }
    public static void main( String[] args ) {
        f.getContentPane().setLayout( new java.awt.GridLayout(8,8) );
        for(int i=7,j=-1;i>=0; f.getContentPane().add(c=o[(j=++j%8)*8+i]=new Sc()),
            c.s = (c.j=j)<8&((c.i=i)<3|i>4)? (i+j)%2*(i/4+1): 0,
            c.setBackground((i+j)%2>0?new java.awt.Color(50,40,130):java.awt.Color.white),
            c.addMouseListener( new java.awt.event.MouseAdapter() {
                public void mousePressed(java.awt.event.MouseEvent e) {
                    f.update(((c=(Sc)e.getSource()).n=e.getButton()>2? c.s=++c.s%5:
                        e.getClickCount()<2?(p[r.L++]=c).s:r.E(8))>-1?f.getGraphics():null);
                }
            }), f.setDefaultCloseOperation(3), f.setSize(650,700), f.setVisible((i-=j/7)<0));
    }
} // LINEA 32 - by Guz

Valid XHTML 1.0! Valid CSS!

questo sito web รจ gestito con Eastweed