head	1.28;
access;
symbols
	tonic_4:1.27
	tonic_3:1.26
	tonic_2:1.25
	demo:1.23.0.2
	design_report:1.23
	oral_presentation_freeze:1.1.0.4
	DAVEG_CDP:1.1.0.2;
locks; strict;
comment	@ * @;


1.28
date	95.12.15.19.54.06;	author daveg;	state Exp;
branches;
next	1.27;

1.27
date	95.12.15.17.09.40;	author daveg;	state Exp;
branches;
next	1.26;

1.26
date	95.12.15.11.09.29;	author daveg;	state Exp;
branches;
next	1.25;

1.25
date	95.12.14.23.57.45;	author jered;	state Exp;
branches;
next	1.24;

1.24
date	95.12.14.23.15.53;	author daveg;	state Exp;
branches;
next	1.23;

1.23
date	95.12.11.18.28.23;	author jered;	state Exp;
branches;
next	1.22;

1.22
date	95.12.11.17.25.37;	author jered;	state Exp;
branches;
next	1.21;

1.21
date	95.12.11.10.39.11;	author daveg;	state Exp;
branches;
next	1.20;

1.20
date	95.12.11.10.31.57;	author daveg;	state Exp;
branches;
next	1.19;

1.19
date	95.12.11.10.22.47;	author daveg;	state Exp;
branches;
next	1.18;

1.18
date	95.12.11.08.18.04;	author daveg;	state Exp;
branches;
next	1.17;

1.17
date	95.12.10.10.51.52;	author daveg;	state Exp;
branches;
next	1.16;

1.16
date	95.12.10.09.08.02;	author daveg;	state Exp;
branches;
next	1.15;

1.15
date	95.12.10.08.30.46;	author daveg;	state Exp;
branches;
next	1.14;

1.14
date	95.12.10.07.57.26;	author daveg;	state Exp;
branches;
next	1.13;

1.13
date	95.12.09.23.26.38;	author daveg;	state Exp;
branches;
next	1.12;

1.12
date	95.12.09.07.54.09;	author daveg;	state Exp;
branches;
next	1.11;

1.11
date	95.12.09.06.32.48;	author daveg;	state Exp;
branches;
next	1.10;

1.10
date	95.12.07.17.15.50;	author daveg;	state Exp;
branches;
next	1.9;

1.9
date	95.12.06.14.12.33;	author daveg;	state Exp;
branches;
next	1.8;

1.8
date	95.12.05.10.53.14;	author daveg;	state Exp;
branches;
next	1.7;

1.7
date	95.12.04.10.32.53;	author daveg;	state Exp;
branches;
next	1.6;

1.6
date	95.12.04.08.44.20;	author daveg;	state Exp;
branches;
next	1.5;

1.5
date	95.12.04.05.47.28;	author daveg;	state Exp;
branches;
next	1.4;

1.4
date	95.12.04.02.46.01;	author daveg;	state Exp;
branches;
next	1.3;

1.3
date	95.12.03.19.56.05;	author hartmans;	state Exp;
branches;
next	1.2;

1.2
date	95.12.01.23.02.42;	author hartmans;	state Exp;
branches;
next	1.1;

1.1
date	95.11.25.05.05.39;	author daveg;	state Exp;
branches
	1.1.2.1;
next	;

1.1.2.1
date	95.11.28.01.43.08;	author daveg;	state Exp;
branches;
next	1.1.2.2;

1.1.2.2
date	95.11.30.10.25.41;	author daveg;	state Exp;
branches;
next	1.1.2.3;

1.1.2.3
date	95.12.01.04.53.09;	author daveg;	state Exp;
branches;
next	1.1.2.4;

1.1.2.4
date	95.12.01.13.58.04;	author daveg;	state Exp;
branches;
next	;


desc
@@


1.28
log
@fixed promotion
@
text
@#include <6170.h>
#include <antichess_board.h>

typeinfo_t antichess_board::typeinfo = new_typeinfo();

antichess_board::antichess_board(istream &initial_format) :
chess_display_board(initial_format) {
}

antichess_board::antichess_board() : chess_display_board() {
}

antichess_board::~antichess_board() {
}

int antichess_board::winner() {
    if (!are_valid_move_available(0, false))
	return 0;
    if (!are_valid_move_available(1, false))
	return 1;
    return -1;
}

board * antichess_board::clone() const {
    antichess_board *ab = new antichess_board();
    board::clone_part(*ab);
    chess_display_board::clone_part(*ab);
    clone_part(*ab);
    return ab;
}

void antichess_board::clone_part(antichess_board &ab) const {
    ab.evaluation = evaluation;
}
	

bool antichess_board::is_legal_move(move &m, int player_num) const {
    chess_capture_move *mv = (chess_capture_move *)
	m.force(chess_capture_move::typeinfo);
    if (!mv)
	return false;
    path route = mv->get_path();
    chess_piece piece = mv->get_piece_taken();
    if (piece == none){
	move_generator *mg = valid_moves(player_num);
	move *cm;
	if (mg->get(cm)) {
	    chess_capture_move *force = (chess_capture_move *)
		cm->force(chess_capture_move::typeinfo);
	    if (!force)
		return false;
	    if (force->get_piece_taken() != none)
		return false;
	}
    }
        
    bool t = move_validity(player_num, route, piece);
    if (!t){
	cout << route.x1 << route.y1 << route.x2 << route.y2 << "\n";
	cout << "given invalid move\n";
	save(cout);
    }
    return t;
}

game::move_result antichess_board::apply(move &m, int player_num){
    chess_capture_move *mv = (chess_capture_move *)
	m.force(chess_capture_move::typeinfo);
    if (!mv)
	return game::move_invalid;
    
    if (!is_legal_move(*mv, player_num))
	return game::move_invalid;
    
    path temp = mv->get_path();
    if ((temp.x1<0) || (temp.x1>7) ||
	(temp.y1<0) || (temp.y1>7) ||
	(temp.x2<0) || (temp.x2>7) ||
	(temp.y2<0) || (temp.y2>7))
	return game::move_invalid;
    square sq1 = fetch(temp.y1,temp.x1);
    if (sq1.piece_type == none)
	return game::move_invalid;
    move_piece(temp.x1,temp.y1,temp.x2,temp.y2, mv->was_promotion());
    return game::ok;
}

game::move_result antichess_board::apply_internal(chess_capture_move *m, 
						  int player_num){
    path temp = m->get_path();
    move_piece(temp.x1, temp.y1, temp.x2, temp.y2, m->was_promotion());
    return game::ok;
}

bool antichess_board::unapply(move &m, int ){
    chess_capture_move *mv =  (chess_capture_move *)
	m.force(chess_capture_move::typeinfo);
    if (!mv)
	return false;
        
    path temp = mv->get_path();
    if ((temp.x1<0) || (temp.x1>7) ||
	(temp.y1<0) || (temp.y1>7) ||
	(temp.x2<0) || (temp.x2>7) ||
	(temp.y2<0) || (temp.y2>7))
	return false;
    square sq1 = fetch(temp.y2,temp.x2);
    if (sq1.piece_type == none)
	return false;
    chess_piece old_piece = mv->get_piece_taken();
    color old_color = mv->get_color_taken();
    move_piece(temp.x2,temp.y2,temp.x1,temp.y1,mv->was_promotion());
    place_piece(temp.x2,temp.y2,old_piece, old_color);
    return true;
}

board::value antichess_board::eval_move_delta(int p_pov, move &m, 
					      int p_mover) const{
    board::value total =0;
    antichess_board *b = (antichess_board *) this;
    chess_capture_move *mv = 
        (chess_capture_move *)m.force(chess_capture_move::typeinfo);
    if (!mv)
        return 0;

    if (!is_legal_move(m, p_mover))
	return 0;
    
    b->apply_internal(mv, p_mover);
    
    if (!are_valid_move_available(p_pov, false)) {
	b->unapply(m, p_mover);
	return board::infinity;
    }
    
    b->unapply(m, p_mover);

    switch(mv->get_piece_taken()){
    case invalid:  break;  //this should never happen
    case none: total =0;
	break;
    case pawn: total= 1;
	break;
    case rook: total= 6;
	break;
    case knight: total= 3;
	break;
    case bishop: total= 6;
	break;
    case queen: total= 10;
	break;
    case king: total= 3;
	break;
    }

    if (mv->was_promotion())
	total += 7;

    if (p_mover == p_pov)
	return -total;
    return total;
}

board::value antichess_board::evaluate(int player_num) const{
    int x1, y1;
    int piece;
    register antichess_board *b = (antichess_board *) this;
    board::value total =0;
    color this_color;
    
    if (!state_changed())
	return evaluation;
    b->update();
    
    if (player_num==0)
	this_color=white;
    else if (player_num==1)
	this_color=black;

    for(y1=0;y1<8;y1++)
	for(x1=0;x1<8;x1++){
	    switch(b->fetch(y1,x1).piece_type){
	    case invalid:  break;  //this should never happen
	    case none:     break;
	    case pawn: piece = 1;
		break;
	    case rook: piece = 6;
		break;
	    case knight: piece = 3;
		break;
	    case bishop: piece = 6;
		break;
	    case queen: piece = 10;
		break;
	    case king: piece = 3;
		break;
	    }
	    if (b->fetch(y1,x1).piece_color == this_color)
		total -= piece;
	    else
		total += piece;
	}
    b->evaluation = total;
    return total;
}

long antichess_board::suggest_time(long time_left) const {
    if ((starting_pieces()-pieces_remaining(0)-pieces_remaining(1)) < 1)
	return (time_left / 60);  // Start game, don't think too hard
  else if ((pieces_remaining(0)+pieces_remaining(1)) < 10)
      return (time_left / 5);
  else return (time_left / (pieces_remaining(0) + pieces_remaining(1)));
}

void * antichess_board::force (typeinfo_t &t){
    if (t == typeinfo) return this;
    else return 0;
}


bool antichess_board::valid_move_available(int player_num) const {
    return are_valid_move_available(player_num, true);
}

@


1.27
log
@tweaked piece values
@
text
@d142 1
a142 5
    case pawn: 
	if (mv->was_promotion())
	    total = 10;
	else
	    total= 1;
d155 4
d208 3
a210 3
  if ((starting_pieces()-pieces_remaining(0)-pieces_remaining(1)) < 1)
    return (time_left / 60);  // Start game, don't think too hard
  else if ((pieces_remaining(0)+pieces_remaining(1)) < 10)  //
@


1.26
log
@fixed not unapplying
@
text
@d144 1
a144 1
	    total = 7;
d148 1
a148 1
    case rook: total= 5;
d152 1
a152 1
    case bishop: total= 5;
d154 1
a154 1
    case queen: total= 7;
d156 1
a156 1
    case king: total= 2;
d187 1
a187 1
	    case rook: piece = 5;
d191 1
a191 1
	    case bishop: piece = 5;
d193 1
a193 1
	    case queen: piece = 7;
d195 1
a195 1
	    case king: piece = 2;
d209 3
a211 3
    return (time_left / 30);  // Start game, don't think too hard
  else if ((pieces_remaining(0)+pieces_remaining(1)) < 10)
    return (time_left / 10);
a212 2
//    return (time_left * (starting_pieces()+1-pieces_remaining(0)
//		  -pieces_remaining(1))) /starting_pieces();
@


1.25
log
@Piece values changed, etc.
@
text
@d131 2
a132 1
    if (!are_valid_move_available(p_pov, false))
d134 1
@


1.24
log
@fixed pawn promotion
@
text
@d183 1
a183 1
	    case pawn: piece = 7;
d185 1
a185 1
	    case rook: piece = 2;
d187 1
a187 1
	    case knight: piece = 4;
d189 1
a189 1
	    case bishop: piece = 2;
d191 1
a191 1
	    case queen: piece = 2;
d193 1
a193 1
	    case king: piece = 6;
@


1.23
log
@Bug fix.
@
text
@d84 1
a84 1
    move_piece(temp.x1,temp.y1,temp.x2,temp.y2);
d91 1
a91 1
    move_piece(temp.x1,temp.y1,temp.x2,temp.y2);
d112 1
a112 1
    move_piece(temp.x2,temp.y2,temp.x1,temp.y1);
d140 5
a144 1
    case pawn: total= 1;
d164 1
a179 3
	    if (b->fetch(y1,x1).piece_color != this_color)
		break;
	
d183 1
a183 1
	    case pawn: total-= 7;
d185 1
a185 1
	    case rook: total-= 2;
d187 1
a187 1
	    case knight: total-= 4;
d189 1
a189 1
	    case bishop: total-= 2;
d191 1
a191 1
	    case queen: total-= 2;
d193 1
a193 1
	    case king: total-= 6;
d196 4
@


1.22
log
@A slightly more sane suggest_time.
@
text
@d181 1
a181 1
	    case pawn: total-= 1;
d183 1
a183 1
	    case rook: total-= 5;
d185 1
a185 1
	    case knight: total-= 3;
d187 1
a187 1
	    case bishop: total-= 5;
d189 1
a189 1
	    case queen: total-= 7;
d191 1
a191 1
	    case king: total-= 2;
@


1.21
log
@bug fixes
@
text
@d200 7
a206 2
    return (time_left * (starting_pieces()+1-pieces_remaining(0)
		  -pieces_remaining(1))) /starting_pieces();
@


1.20
log
@bug fixes
@
text
@d200 2
a201 2
    return (time_left * starting_pieces()+1-pieces_remaining(0)
		  -pieces_remaining(1)) /starting_pieces();
@


1.19
log
@bug fixes
@
text
@d200 2
a201 2
    return (starting_pieces()+1-pieces_remaining(0)-pieces_remaining(1)) 
	/starting_pieces() * time_left;
@


1.18
log
@added suggest_time
@
text
@d200 2
a201 2
    return (starting_pieces()+5-pieces_remaining(0)-pieces_remaining(1)) 
	* time_left;
@


1.17
log
@bug fix
@
text
@d199 4
@


1.16
log
@bug fix
@
text
@d107 1
a107 1
    square sq1 = fetch(temp.y1,temp.x1);
@


1.15
log
@added apply_internal
@
text
@d76 4
a79 4
    if ((temp.x1>=0) || (temp.x1<=7) ||
	(temp.y1>=0) || (temp.y1<=7) ||
	(temp.x2>=0) || (temp.x2<=7) ||
	(temp.y2>=0) || (temp.y2<=7))
d102 4
a105 4
    if ((temp.x1>=0) || (temp.x1<=7) ||
	(temp.y1>=0) || (temp.y1<=7) ||
	(temp.x2>=0) || (temp.x2<=7) ||
	(temp.y2>=0) || (temp.y2<=7))
@


1.14
log
@fixed apply and unapply to meet spec
@
text
@d88 6
d128 2
a129 2

    b->apply(m, p_mover);
d133 1
a133 1

@


1.13
log
@added eval_move_delta
@
text
@d76 8
d96 8
@


1.12
log
@changed eval_move_delta header
@
text
@a103 3
    if (state_changed())
	b->evaluate(p_pov);
    
d105 3
a107 1
	return -1;
d109 5
d131 2
a139 1
    int pieces_to_find;
a150 2
    pieces_to_find = pieces_remaining(player_num);
            
d159 1
a159 1
	    case pawn: total+= 1;
d161 1
a161 1
	    case rook: total+= 5;
d163 1
a163 1
	    case knight: total+= 3;
d165 1
a165 1
	    case bishop: total+= 5;
d167 1
a167 1
	    case queen: total+= 7;
d169 1
a169 1
	    case king: total+= 2;
@


1.11
log
@added piece captures
@
text
@d95 2
a96 1
board::value antichess_board::eval_move_delta (move &m, int player_num) const{
d105 1
a105 1
	b->evaluate(player_num);
d107 1
a107 1
    if (!is_legal_move(m, player_num))
@


1.10
log
@and even more bug fixes
@
text
@d44 13
a65 1

a182 1

@


1.9
log
@bug fixes
@
text
@d44 7
a50 1
    return move_validity(player_num, route, piece);
a87 1
    // Previous line managed to seg fault on me!!!
@


1.8
log
@a few more bug fixes
@
text
@d82 1
@


1.7
log
@bug fixes
@
text
@d17 1
a17 1
    if (!valid_move_available(0))
d19 1
a19 1
    if (!valid_move_available(1))
d162 3
@


1.6
log
@bug fixes
@
text
@d38 2
a39 1
    chess_capture_move *mv = (chess_capture_move *)m.force(chess_capture_move::typeinfo);
d43 2
a44 9
    square from = fetch(route.x1, route.y1);
    color c;
    if (player_num ==0)
	c = white;
    if (player_num == 1)
	c = black;
    if (from.piece_color != c)
	return false;
    return move_validity(player_num, from.piece_type, from.piece_color, route);
@


1.5
log
@bug fixes and cloning stuff
@
text
@a15 1
// Still needs to be done
d17 5
a21 1
    return 1;
d85 1
a85 1
    register antichess_board *b = (antichess_board *) this;
@


1.4
log
@bug fixes
@
text
@d10 2
d16 17
d51 4
a54 2
game::move_result antichess_board::apply(chess_capture_move &m, int player_num){
    if (!is_legal_move(m, player_num))
d57 4
a60 1
    path temp = m.get_path();
d66 9
a74 4
bool antichess_board::unapply(chess_capture_move &m, int ){
    path temp = m.get_path();
    chess_piece old_piece = m.get_piece_taken();
    color old_color = m.get_color_taken();
a77 5
}


void antichess_board::display(extensions *ext, ostream &body, int
			      player_num) const{
@


1.3
log
@Make antichess/Makefile

	This sort of compiles until you get to antichess_board.C.
@
text
@d28 1
a28 1
    return move_validity(from.piece_type, from.piece_color, route);
d97 1
a97 1
    if (state_changed())
@


1.2
log
@Integrate Antichess boarrd from DAVEG_CPD
@
text
@d1 1
d4 1
a4 1
antichess_board::typeinfo = new_typeinfo();
d42 1
a42 1
bool antichess_board::unapply(chess_capture_move &m, int player_num){
a50 2
http_response *antichess_board::get(string request, extensions *extras){
}
@


1.1
log
@rough sketch of antichess_board
@
text
@d5 2
a6 45
antichess_board::antichess_board(istream &initial_format) {
    char ch;
    int x;
    square insertion;
    column temp;

    brd.predict(8);
    for(x=0;x<8;x++){
	brd.append(temp);
	brd[x].predict(8);
    }
    
    initialization_success= true;
    x=0;
    while((x<64) && (initial_format.good()) && (initial_format >> ch)) {
	insertion= ctosquare(ch);
	if (x % 2)
	    insertion.square_color = white;
	else
	    insertion.square_color = black;
	if (insertion.piece_type == invalid) {
	    initialization_success = false;
	    break;
	}
	insertion.square_type = normal;
	brd[x / 8].append(insertion);
	x++;
    }
    if (x != 64)
	initialization_success = false;
    
    if (!initialization_success){
	cerr << "Invalid board format\n";
	for(x=0;x<8;x++)
	    brd[x].clear();
	for(x=0;x<64;x++){
	    if (x % 2)
		insertion.square_color = white;
	    else
		insertion.square_color = black;
	    insertion.piece_type = none;
	    insertion.square_type = normal;
	    brd[x / 8].append(insertion);
	}
    }
d14 14
a27 2
bool antichess_board::is_legal_move(move &m, const player *p) const {
    
d31 7
a37 1
game::move_result antichess_board::apply(move &m, player *p){
d41 7
a47 1
bool antichess_board::unapply_move(move &m, const player *p){
d53 2
a54 1
void antichess_board:display(extensions *ext, ostream &body) const{
d57 7
a63 2
bool antichess_board::valid_move_available(const player *p) const{
}
d65 24
a88 1
generator <move> * antichess_board::valid_moves(const player *p) const{
d91 42
a132 1
board::value antichess_board::eval_move_delta (move &m, const player *p) const{
a134 2
board::value antichess_board::evaluate(const player *p) const{
}
d141 3
@


1.1.2.1
log
@test move validation code
@
text
@a4 3
// Note: this is an exact copy of what's in chess_display_board.C for
// now, but I expect it to change as they give us new stuff for an
// antichess game to deal with.
a58 8
    chess_move mv = m.force( );
    if (!mv)
	return false;
    path route = mv->get_path();
    square from = fetch(route.x1, route.y1);
    if (from.piece_color != p->get_name)
	return false;
    return move_validity(from.piece_type, route);
@


1.1.2.2
log
@updated headers
@
text
@d5 48
a52 2
antichess_board::antichess_board(istream &initial_format) :
chess_display_board(initial_format) {
d60 3
a62 2
bool antichess_board::is_legal_move(move &m, int player_num) const {
    chess_capture_move mv = m.force(chess_capture_move::typeinfo);
d65 1
a65 1
    path route = mv.get_path();
d67 1
a67 6
    color c;
    if (player_num ==0)
	c = white;
    if (player_num == 1)
	c = black;
    if (from.piece_color != c)
d69 1
a69 1
    return move_validity(from.piece_type, from.piece_color, route);
d73 1
a73 3
game::move_result antichess_board::apply(chess_capture_move &m, int player_num){
    path temp = m.get_path();
    move_piece(temp.x1,temp.y1,temp.x2,temp.y2);
d77 1
a77 3
bool antichess_board::unapply_move(chess_capture_move &m, int player_num){
    path temp = m.get_path();
    move_piece(temp.x2,temp.y2,temp.x1,temp.y1);
d83 1
a83 2
void antichess_board::display(extensions *ext, ostream &body, int
			      player_num) const{
d86 1
a86 1
board::value antichess_board::eval_move_delta (move &m, int player_num) const{
d89 7
a95 1
board::value antichess_board::evaluate(int player_num) const{
a101 3



@


1.1.2.3
log
@general clean up
@
text
@a52 32
    int x1, y1;
    antichess_board &b = *this;
    board::value total =0;
        
    for(y1=0;y1<8;y1++)
	for(x1=0;x1<8;x1++){
	    if (b(y1,x1).piece_color != this_color)
		break;
	
	    switch(b(y1,x1).piece_type){
	    case invalid:  break;  //this should never happen
	    case none:     break;
	    case pawn: total+= ;
		break;
	    case rook: total+= ;
		break;
	    case bishop: total+= ;
		break;
	    case queen: total+= ;
		break;
	    case king: total+= ;
		break;
	    }
	}
    return total;
}

		
		
		
		

@


1.1.2.4
log
@finished evaluate
@
text
@d15 1
a15 1
    chess_capture_move *mv = (chess_capture_move *)m.force(chess_capture_move::typeinfo);
d18 1
a18 1
    path route = mv->get_path();
a31 3
    if (!is_legal_move(m, player_num))
	return game::move_invalid;
    
a33 1
    return game::ok;
d37 1
a37 1
bool antichess_board::unapply(chess_capture_move &m, int player_num){
a38 2
    chess_piece old_piece = m.get_piece_taken();
    color old_color = m.get_color_taken();
a39 2
    place_piece(temp.x2,temp.y2,old_piece, old_color);
    return true;
a49 31
    board::value total =0;
    register antichess_board *b = (antichess_board *) this;
    chess_capture_move *mv = 
        (chess_capture_move *)m.force(chess_capture_move::typeinfo);
    if (!mv)
        return 0;

    if (state_changed())
	b->evaluate(player_num);
    
    if (!is_legal_move(m, player_num))
	return -1;
    
    switch(mv->get_piece_taken()){
    case invalid:  break;  //this should never happen
    case none: total =0;
	break;
    case pawn: total= 1;
	break;
    case rook: total= 5;
	break;
    case knight: total= 3;
	break;
    case bishop: total= 5;
	break;
    case queen: total= 7;
	break;
    case king: total= 2;
	break;
    }
    return total;
d54 1
a54 1
    register antichess_board *b = (antichess_board *) this;
d56 1
a56 14
    int pieces_to_find;
    color this_color;
    
    if (state_changed())
	return evaluation;
    b->update();
    
    if (player_num==0)
	this_color=white;
    else if (player_num==1)
	this_color=black;

    pieces_to_find = pieces_remaining(player_num);
            
d59 1
a59 1
	    if (b->fetch(y1,x1).piece_color != this_color)
d62 1
a62 1
	    switch(b->fetch(y1,x1).piece_type){
d65 1
a65 3
	    case pawn: total+= 1;
		break;
	    case rook: total+= 5;
d67 1
a67 1
	    case knight: total+= 3;
d69 1
a69 1
	    case bishop: total+= 5;
d71 1
a71 1
	    case queen: total+= 7;
d73 1
a73 1
	    case king: total+= 2;
a76 1
    b->evaluation = total;
d80 6
@
