Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

games

natas14natas14 Posts: 1Member
can anybody tell me how to program a chess moves!!?

Comments

  • mac_doggiemac_doggie Posts: 488Member
    : can anybody tell me how to program a chess moves!!?
    :
    maybe this will get ya goin ?

    [code]



    function Chessboard() {
    this.a = new Array();
    this.b = new Array();
    this.c = new Array();
    this.d = new Array();
    this.e = new Array();
    this.f = new Array();
    this.g = new Array();
    this.h = new Array();

    this.NewGame = chb_NewGame;
    this.Move = chb_Move;
    }

    function chb_NewGame() {
    // place the black pieces
    //
    this.a[1] = 'black tower';
    this.a[2] = 'black horse';
    this.a[3] = 'black knight';
    this.a[4] = 'black queen';
    this.a[5] = 'black king';
    this.a[6] = 'black knight';
    this.a[7] = 'black horse';
    this.a[8] = 'black tower';
    this.b[1] = 'black pion';
    this.b[2] = 'black pion';
    this.b[3] = 'black pion';
    this.b[4] = 'black pion';
    this.b[5] = 'black pion';
    this.b[6] = 'black pion';
    this.b[7] = 'black pion';
    this.b[8] = 'black pion';

    // place the white pieces
    //
    this.g[1] = 'white tower';
    this.g[2] = 'white horse';
    this.g[3] = 'white knight';
    this.g[4] = 'white queen';
    this.g[5] = 'white king';
    this.g[6] = 'white knight';
    this.g[7] = 'white horse';
    this.g[8] = 'white tower';
    this.h[1] = 'white pion';
    this.h[2] = 'white pion';
    this.h[3] = 'white pion';
    this.h[4] = 'white pion';
    this.h[5] = 'white pion';
    this.h[6] = 'white pion';
    this.h[7] = 'white pion';
    this.h[8] = 'white pion';

    // initialise the rest of the board with empty squares
    //
    for(var i=1;i<9;i++) {
    this.c[i] = '';
    this.d[i] = '';
    this.e[i] = '';
    this.f[i] = '';
    }
    }

    function chb_Move(x1, y1, x2, y2) {
    eval( 'piece = this.'+x1+'['+y1+'];');
    alert(piece);
    // check the validity of the move
    //
    if(piece.substring(6,11) == 'tower') {
    // check the validity of the move if it is a tower piece...
    //
    var validmove = true;
    }
    if(piece.substring(6,11) == 'horse') {
    // check the validity of the move if it is a tower piece...
    //
    var validmove = true;
    }
    // etc...


    // If the move is valid...
    //
    if(validmove) {
    eval( 'this.'+x1+'['+y1+'] = "";');
    eval( 'this.'+x2+'['+y2+'] = "'+piece+'";');
    alert('move was valid');
    }else {
    alert('invalid move...');
    }

    }

    var game = new Chessboard();
    game.NewGame();
    game.Move('a',1,'b',1);
    </script>




    [/code]
    ;-)
    -mac-
    mailto:mac_doggie@hotmail.com
    the Netherlands...


Sign In or Register to comment.