View Single Post
  #40  
Old 02-11-2006, 03:15 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Quote:
Originally Posted by ApothiX
The thought was taken seriously. The problem is that a scripting collab just will not work as expected without a set objective. Also, I knew who the poster in question was, and my opinion stayed the same as it would have for any other person posting this.
Oh, so I take it that nobody's going to take my objective.

Let me start you off since I actually started making a chess script a long long time ago (but since it's old, it might not be as good).

Class Knight:
PHP Code:
function check_move(newx,newy,oldx,oldy) {
  return 
dist(oldx,newx,oldy,newy) == 5^0.5;

Class King:
PHP Code:
function check_move(newx,newy,oldx,oldy) {
  return 
dist(oldx,newx,oldy,newy) <= 1.5;

Class Pawn (as I said, the hardest):
PHP Code:
function check_move(newx,newy,oldx,oldy) {
  
this.dist dist(oldx,newx,oldy,newy);
  if (
this.dist 2) return 0;
  else if ((
newy oldy) * this.test_a 0) return 0;
  else if (
oldx != newx) {
    if (
this.dist != 2^0.5) return 0;
    else return 
level.chessboard[oldy][oldx] * level.chessboard[newy][newx] != 0;
  } else if (
level.chessboard[oldy+this.test_a][oldx] != 0) return 0;
  else if (
this.dist == 2) {
    if (
level.chessboard[newy][newx] != 0) return 0;
    else return 
oldy == this.test_a 3.5 * (this.test_a 1);
  } else return 
1;
}
//I don't even remember what this.test_a is anymore. 
Useful functions for queen/bishop/rook:
PHP Code:
function check_jump(newx,newy,oldx,oldy) {
  
newx;
  
newy;
  while (
!= oldx || != oldy) {
    
+= attdir(oldx newx);
    
+= attdir(oldy newy);
    if (
== oldx && == oldy) return 1;
    else if (
level.chessboard[j][i] != 0) return 0;
  }
}

function 
check_diagonal(newx,newy,oldx,oldy) {
  if (
abs(newx oldx) != abs(newy oldy)) return 0;
  else return 
check_jump(newx,newy,oldx,oldy);
}

function 
check_straight(newx,newy,oldx,oldy) {
  if (!(
newx == oldx || newy == oldy)) return 0;
  else return 
check_jump(newx,newy,oldx,oldy);

I believe level.chessboard saves booleans for whether the square on the board is occupied?
Reply With Quote