Simple Chess

De DigiWiki.

So as it stands, make a piece named White and add the piece script and duplicate it until you have 12 pieces named white (essential that they are named correctly) now duplicate one once more and change the name to Black and add a dark color and duplicate it to 12 black pieces.

Now make 2 prims the same width as the board and about 2 squares deep, and add the "Home" script, then make a board, making sure you link in this exact order...12 white pieces, then 12 black pieces, then 2 home pieces then board last.

it doesnt matter where the pieces are so long as they are on the board, click one of the home prims and you will get a dropdown, click Reset, and the pieces should set themselves up.

Starting from about line 90 on the board script is where I am trying to isolate the opposition piece to be taken (in respect to the piece taking it) thats where it fails, any advice or tips would be greatly appreciated. All the llSay stuff like "match" is just debug to tell me whats happening. If you run the game and get a black piece where it can be taken, then move a white piece onto the black place we should have a match, look thru the debug spam, you will see one position exactly matches the black position, yet I get "no match" [pulls hair out] (every time you click to move a white, it says the position of every black on the board, and the position where the white would land((on the black, for testing) as in chess, havent scripted the completed jump yet)

Sorry to get long winded but I would rather that than just say here it is, fix it, fix it, fix it.

Thanks, Cam Chevalier.

// checkers reset (set up board) script V0.1 by Cam Chevalier
// Put this script in a prim 8 squares wide and 2 squares long called "home" and put one one each end of the board, these Home prims to be linked just before the board to be set as child 2 and child 3
 
list choice = ["reset"];
string msg = "\n\nRESET GAME\n\n Are you sure?";
key ToucherID;
integer listen_id;
list size;
 
default{
  touch_start(integer total_number) {
    ToucherID = llDetectedKey(0);
    llDialog(ToucherID, msg, choice, 4567);
    listen_id = llListen( 4567, "", ToucherID, "");
    llSetTimerEvent(60); //HERE WE SET A TIME LIMIT
  }
 
  listen(integer channel, string name, key id, string choice) { 
if (choice == "reset") {
        llSay(0,"you chose reset");
        size = llGetLinkPrimitiveParams(1,[PRIM_SIZE]);
       // llSay(0,(string)size);
 
        vector vsize = llList2Vector(size,0);
            float wFactor=vsize.x/8;
            float wstep = wFactor/2; 
            float hFactor=vsize.y/8;
            float hstep = hFactor/2;
            float tFactor=vsize.z;
             llSay(0,(string)vsize);
 
        llMessageLinked(LINK_SET,0,"Reset Scripts","");
        //////////////////////////set white pieces/////////////////
       vector place1= ( <-(wstep+wFactor*3),-(hstep+hFactor*3),tFactor>);
        llSetLinkPrimitiveParams(4,[PRIM_POSITION,place1]);
         vector place2= ( <-(wstep+wFactor),-(hstep+hFactor*3),tFactor>);
        llSetLinkPrimitiveParams(5,[PRIM_POSITION,place2]);
          vector place3= ( <wstep,-(hstep+hFactor*3),tFactor>);
        llSetLinkPrimitiveParams(6,[PRIM_POSITION,place3]);        
        vector place4= ( <wstep+wFactor*2,-(hstep+hFactor*3),tFactor>);
        llSetLinkPrimitiveParams(7,[PRIM_POSITION,place4]); 
 
          vector place5= ( <-(wstep+wFactor*2),-(hstep+hFactor*2),tFactor>);
        llSetLinkPrimitiveParams(8,[PRIM_POSITION,place5]);       
        vector place6= ( <-wstep,-(hstep+hFactor*2),tFactor>);
        llSetLinkPrimitiveParams(9,[PRIM_POSITION,place6]); 
        vector place7= ( <(wstep+wFactor),-(hstep+hFactor*2),tFactor>);
        llSetLinkPrimitiveParams(10,[PRIM_POSITION,place7]); 
         vector place8= ( <(wstep+wFactor*3),-(hstep+hFactor*2),tFactor>);
        llSetLinkPrimitiveParams(11,[PRIM_POSITION,place8]);
 
       vector place9= ( <-(wstep+wFactor*3),-(hstep+hFactor),tFactor>);
        llSetLinkPrimitiveParams(12,[PRIM_POSITION,place9]);
         vector place10= ( <-(wstep+wFactor),-(hstep+hFactor),tFactor>);
        llSetLinkPrimitiveParams(13,[PRIM_POSITION,place10]);
          vector place11= ( <wstep,-(hstep+hFactor),tFactor>);
        llSetLinkPrimitiveParams(14,[PRIM_POSITION,place11]);        
        vector place12= ( <wstep+wFactor*2,-(hstep+hFactor),tFactor>);
        llSetLinkPrimitiveParams(15,[PRIM_POSITION,place12]); 
   ////////////////////////////////set black pieces  
           vector place13= ( <-(wstep+wFactor*2),(hstep+hFactor),tFactor>);
        llSetLinkPrimitiveParams(16,[PRIM_POSITION,place13]);       
        vector place14= ( <-wstep,(hstep+hFactor),tFactor>);
        llSetLinkPrimitiveParams(17,[PRIM_POSITION,place14]); 
        vector place15= ( <(wstep+wFactor),(hstep+hFactor),tFactor>);
        llSetLinkPrimitiveParams(18,[PRIM_POSITION,place15]); 
         vector place16= ( <(wstep+wFactor*3),(hstep+hFactor),tFactor>);
        llSetLinkPrimitiveParams(19,[PRIM_POSITION,place16]);
 
        vector place17= ( <-(wstep+wFactor*3),(hstep+hFactor*2),tFactor>);
        llSetLinkPrimitiveParams(20,[PRIM_POSITION,place17]);
         vector place18= ( <-(wstep+wFactor),(hstep+hFactor*2),tFactor>);
        llSetLinkPrimitiveParams(21,[PRIM_POSITION,place18]);
          vector place19= ( <wstep,(hstep+hFactor*2),tFactor>);
        llSetLinkPrimitiveParams(22,[PRIM_POSITION,place19]);        
        vector place20= ( <wstep+wFactor*2,(hstep+hFactor*2),tFactor>);
        llSetLinkPrimitiveParams(23,[PRIM_POSITION,place20]); 
 
          vector place21= ( <-(wstep+wFactor*2),(hstep+hFactor*3),tFactor>);
        llSetLinkPrimitiveParams(24,[PRIM_POSITION,place21]);       
        vector place22= ( <-wstep,(hstep+hFactor*3),tFactor>);
        llSetLinkPrimitiveParams(25,[PRIM_POSITION,place22]); 
        vector place23= ( <(wstep+wFactor),(hstep+hFactor*3),tFactor>);
        llSetLinkPrimitiveParams(26,[PRIM_POSITION,place23]); 
         vector place24= ( <(wstep+wFactor*3),(hstep+hFactor*3),tFactor>);
        llSetLinkPrimitiveParams(27,[PRIM_POSITION,place24]);
 
        llSetText("",<1.0, 0.0, 1.0>, 1.0);
        //llSay(0,(string)place1);
        llListenRemove(listen_id); 
    }
  }
 
  timer() { //switch off listen after 60 seconds
    llListenRemove(listen_id);
    llWhisper(0, "Listen function expired");
    llSetTimerEvent(0.0); //Stop the timer from being called repeatedly
  }
}
// piece script V-0.4 by Cam Chevalier (09-June-2012)
// Put in 12 prims named White and 12 prims named Black and link all 24 first ,then 2 home prims, then board prim then link.
 
vector where;
integer crown=0;
 
default
{ 
    touch_start(integer b)
    {
        where = llGetLocalPos();
        llSay(0,"moving");  
        llMessageLinked(1, crown,(string)where, NULL_KEY);//sending message to root prim
    }
    link_message(integer sender_num, integer num, string str, key id)
    {
        llSetPos(str);
        if ((num==1)&&(crown==0))
        {
            llSetText("KING",<1.0, 0.0, 1.0>, 1.0);
            llSay(0, "***Crown Me***"); crown=1;
        }
        else if (crown==0)
        {
            llSetText("",<1.0, 0.0, 1.0>, 1.0);
        }
        if("Reset Scripts"==str)
        {
            llResetScript();
            llSetText("",<1.0, 0.0, 1.0>, 1.0);
        } 
    }             
}
//Simple chess board script V0.4 by Cam Chevalier (09-June-2012)
 
integer width = 8;
integer height = 8;
integer child;  
integer player;
integer turn= 1;
vector where;
integer king =0; 
integer crown=0;
vector boardv;
vector bplacesv;
 
default
{
    link_message(integer sender_num, integer num, string str, key id)//receiving message from child prim
    {
        list piece=llGetLinkPrimitiveParams(4,[PRIM_SIZE]);
        vector piecev=llList2Vector(piece,0);
        float piecez=(piecev.x*0.5);//half the height of a piece
 
        list board=llGetLinkPrimitiveParams(1,[PRIM_POSITION]);
         boardv=llList2Vector(board,0);
        float boardz=(boardv.x);//z position of the centre of the board
 
        list boardthick=llGetLinkPrimitiveParams(1,[PRIM_SIZE]);
        vector boardthickv=llList2Vector(boardthick,0);
        float boardthickz=(boardthickv.x*0.5);//half the thickness of board
         float btop=boardthickz+boardz;//z position of top of board     
        float tFactor = btop+piecez;         
        child=sender_num; crown =num; where =str;
        if("Reset Scripts"==str)
        {
            llResetScript();
        }
    }
 
    touch_start(integer b)
    {
        //llSay(0,"where.x=" +where.x+"where.y=" +where.y+player);
        if ((child>3) && (child<16)){player=1;} 
        else if ((child>15)&&(child<28)){player=2;}
        llSay(0,"turn"+(string)turn+"player"+(string)player+"child"+(string)child);
        if (player==turn)
        {   
            vector st = llDetectedTouchST(0);
            integer x = llFloor(st.x * width);
            integer y = llFloor(st.y * height);        
            vector size = llGetScale();
            float wFactor=size.x/8;
            float wstep = wFactor/2; 
            float hFactor=size.y/8;
            float hstep = hFactor/2;
            float tFactor=size.z;
 
            vector placex;
            if (x==0){ placex= ( -<wstep+wFactor*3,0,0>);}
            if (x==1){ placex= ( -<wstep+wFactor*2,0,0>);}
            if (x==2){ placex= ( -<wstep+wFactor,0,0>);}
            if (x==3){ placex= ( -<wstep,0,0>);}
            if (x==4){ placex= ( <wstep,0,0>);}
            if (x==5){ placex= ( <wstep+wFactor,0,0>);}
            if (x==6){ placex= ( <wstep+wFactor*2,0,0>);}
            if (x==7){ placex= ( <wstep+wFactor*3,0,0>);}        
            vector placexy;
            if (y==0){ placexy= (placex -<0,hstep+hFactor*3,0>);}
            if (y==1){ placexy= (placex -<0,hstep+hFactor*2,0>);}
            if (y==2){ placexy= (placex -<0,hstep+hFactor,0>);}
            if (y==3){ placexy= (placex -<0,hstep,0>);}
            if (y==4){ placexy= (placex +<0,hstep,0>);}
            if (y==5){ placexy= (placex +<0,hstep+hFactor,0>);}
            if (y==6){ placexy= (placex +<0,hstep+hFactor*2,0>);}
            if (y==7){ placexy= (placex +<0,hstep+hFactor*3,0>);}
            vector finalpos = placexy+<0,0,tFactor>;
            float rfpy =(llRound (finalpos.y*100))*.01;
////////////////////allowable moves player 1 White//////////////
            if (player==1)
            {
               list bplaces;
 
       for (b=16; b<28; b++)
        {
        bplaces=llGetLinkPrimitiveParams( b,[PRIM_POSITION]);
        bplacesv=llList2Vector(bplaces,0);
        bplacesv =(<((llRound(bplacesv.x*100))*.01),((llRound (bplacesv.y*100))*.01),bplacesv.z>)-boardv;     
        llSay(0,"where he is"+ (string)bplacesv);//+"where"+(string)where);
        llSay(0,"where I am going"+(string)<(where.x-wFactor),(where.y+hFactor),where.z>);
       // vector vec1=<(where.x+wFactor),(where.y+hFactor),where.z>;
       // vector vec2=<(where.x-wFactor),(where.y+hFactor),where.z>;
 
        if ((bplacesv==<(where.x+wFactor),(where.y+hFactor),where.z>)||(bplacesv==<(where.x-wFactor),(where.y+hFactor),where.z>))
 
        {llSay(0, "match"); 
        //llSay(0, (string)bplaces+(string)where+(string) wFactor+(string)hFactor);
       }
       else {llSay(0,"no match");}//llSay(0, (string)bplacesv);//+(string)where+(string) wFactor+(string)hFactor);
        }//llSay(0,(string)bplacesv+ (string)where);
 
        ///////////////////////////////////////
                king=0;
                if ((finalpos.y< where.y)&&(crown==0))
                    {llSay(0,"Cant move backwards");} 
                else if (rfpy>where.y+hFactor)
                {llSay(0,"Cant move that many places");}
                else if (finalpos.x>(where.x+wFactor))
                {llSay(0,"Cant move that many places");}
                else if (finalpos.x<(where.x-wFactor))
                {llSay(0,"Cant move that many places");}
                else if (rfpy<(where.y-hFactor))
                {llSay(0,"Cant move that many places");}
                else if (where.x==finalpos.x)
                {llSay(0,"Illegal move");} 
                else if (where.y==rfpy)
                {llSay(0,"Illegal move");}     
                else   
                {  
                    if (y==7){king=1;}
                    llSay(0, (string)y+(string)king);
                    //llSay(0,"wx="+where.x+"wfinal="+finalpos.x);
                    //llSay(0,"wy="+where.y+"yfinal="+finalpos.y);
                    llMessageLinked(child, king,(string)finalpos, NULL_KEY);//sending message to child prim white
                    turn=2;    
                }  
            }  
////////////////////allowable moves player 2 Black//////////////
            else if (player==2)
            {
                king=0;
                if ((finalpos.y> where.y)&&(crown==0)){llSay(0,"Cant move backwards");}
                else if (rfpy<(where.y-hFactor))        
                {llSay(0,"Cant move that many places");}
                else if(finalpos.x>where.x+wFactor)
                {llSay(0,"Cant move that many places");}   
                else if(finalpos.x<(where.x-wFactor))
                {llSay(0,"Cant move that many places");}
                else if (rfpy>(where.y+hFactor))
                {llSay(0,"Cant move that many places");}           
                else if (where.x==finalpos.x)
                {llSay(0,"Illegal move");}
                else if (where.y==rfpy)
                {llSay(0,"Illegal move");}
                else   
                { 
                    if (y==0){king=1;}
                    llSay(0, (string)y+(string)king);
                    llMessageLinked(child, king,(string)finalpos, NULL_KEY);//sending message to child prim black
                turn=1;
                }  
            }             
        }
        else {llSay(0,"Not your turn");}
    }
}
Outils personnels
  • Cette page a été consultée 765 fois.
donate
Google Ads