예제 #1
0
void undo(){
	movepiece(move1.erow,move1.ecol,move1.srow,move1.scol);
	board[move1.erow][move1.ecol]=move1.prevval;
	movepiece(-1,-1,move1.erow,move1.ecol);
	if((move1.prevval!=0)&&(move1.newval!=0))
		count--;
	printelement();
	check();
}
예제 #2
0
/*
	Runs when game_state == WAITING
*/
int state_waiting() {

	Debug_UART_PutString("WAITING");

	// write ".gib"
	strcpy(bres8, "");
    //esp_transmit(bstr_gib, "4");
    //strncpy(bres8, recv, 8);
    
	while(bres8[1] == 0x00) {
		CyDelay(5000);

		esp_transmit(bstr_gib, "4");
        strncpy(bres8, recv, 8);
        
		Debug_UART_PutString(bres8);

		if(bres8[0] == 0x31 || bres8[0] == '1'){
			game_state = CONNECTED;
			break;
		}
	}
	if(bres8[0] == 0x31 || bres8[0] == '1'){
		game_state = CONNECTED;
		return game_state;
	}
	char movementOpp1[4] = { bres8[1], bres8[0], bres8[3], bres8[2] };
	char movementOpp2[4] = { bres8[5], bres8[4], bres8[7], bres8[6] };

	if(	movementOpp2[0] != 0 && movementOpp2[1] != 0 && 
		movementOpp2[2] != 0 && movementOpp2[3] != 0) {
		Debug_UART_PutString(movementOpp2);
        move.fromCol = (int) movementOpp2[0];
        move.fromRow = (int) movementOpp2[1];
        move.toCol = (int) movementOpp2[2];
        move.toRow = (int) movementOpp2[3];
		movepiece(move);
	}
	Debug_UART_PutString(movementOpp1);
    move.fromCol = (int) movementOpp1[0];
    move.fromRow = (int) movementOpp1[1];
    move.toCol = (int) movementOpp1[2];
    move.toRow = (int) movementOpp1[3];
	movepiece(move);

	game_state = MOVING;
	return game_state;
}
예제 #3
0
파일: chess.c 프로젝트: pkova/noobchess
    void rookmover(char* square) {

            if (rooklooper(square) == "-1")
                printf("No rook can move to %s\n", square);
            

            else if (rooklooper(square) == "0")
                printf("Specify which rook to move to %s\n", square);
            

            else {
                char* rookis = rooklooper(square);
                movepiece(rookis, square);

                if (rookis == "a1")
                    wqrookmov = 1;

                else if (rookis == "h1")
                    wkrookmov = 1;

                else if (rookis == "a8")
                    bqrookmov = 1;
                
                else if (rookis == "h8")
                    bkrookmov = 1;
            }
        }
예제 #4
0
파일: chess.c 프로젝트: pkova/noobchess
    void kingmover(char* square) {

            if (kinglooper(square) == "-1")
                printf("No king can move to %s\n", square);

            else {
                char* kingis = kinglooper(square);
                movepiece(kingis, square);
                (wturn == 1) ? (kwmov = 1) : (kbmov = 1);
            }
    }
예제 #5
0
파일: chess.c 프로젝트: pkova/noobchess
    void knightmover(char* square, char* knight) {

            if (knightlooper(square, knight) == "0") 
                printf("Illegal move\n");

            else if (knightlooper(square, knight) == "1")
                printf("Specify which knight to move\n");
            
            else {
                char* knightis = knightlooper(square, knight);
                movepiece(knightis, square);
            }
    }
예제 #6
0
파일: chess.c 프로젝트: pkova/noobchess
    void queenmover(char* square) {

            if (queenlooper(square) == "-1")
                printf("No queen can move to %s\n", square);

            else if (queenlooper(square) == "0")
                printf("Specify which queen to move to %s\n", square);

            else {
                char* queenis = queenlooper(square);
                movepiece(queenis, square);
            }
        }
예제 #7
0
파일: nmm.c 프로젝트: ryanakca/nmm
/*
 * Phases two and three of the game
 */
point *
phasetwothree(scrgame *sg)
{
  point *p = NULL;
  char coords[6];
  while (sg->game->pieces[WHITE] >= 3 && sg->game->pieces[BLACK] >= 3) {
    if (sg->game->pieces[sg->game->state] > 3 && surrounded(sg->game)) {
      update_scorebox(sg->score_w, sg->game);
      update_board(sg->board_w, sg->game);
      return NULL;
    }
    getmove(sg, coords, 0);
    if (!(p = getpoint(sg->game, coords))) {
      update_msgbox(sg->msg_w, "Something went wrong...");
      continue;
    }
    if (p->v != statechar(sg->game)) {
      update_msgbox(sg->msg_w, "Please move your own piece.");
      continue;
    }
    if (sg->game->pieces[sg->game->state] == 3) {
      if (!(p = jumppiece(p, sg->game, &coords[2]))) {
	update_msgbox(sg->msg_w,
		      "That location is already occupied. Please try again");
	continue;
      }
    } else if (!(p = movepiece(p, &coords[2]))) {
      update_msgbox(sg->msg_w,
		    "That location is already occupied. Please try again");
      continue;
    }
    if (inmill(p)) {
      /* We should redraw the board now so that the player can see the
	 piece he just played */
      update_scorebox(sg->score_w, sg->game);
      update_board(sg->board_w, sg->game);
      update_msgbox(sg->msg_w, "");
      mill_handler(sg, coords, 0);
    }
    sg->game->state ^= BLACK;
    if (sg->game->pieces[BLACK] == 3 || sg->game->pieces[WHITE] == 3) {
      sg->game->phase = 3;
    }
    update_scorebox(sg->score_w, sg->game);
    update_board(sg->board_w, sg->game);
    update_msgbox(sg->msg_w, "");
  }
  return p;
}
예제 #8
0
파일: chess.c 프로젝트: pkova/noobchess
    void bishopmover(char* square) {

            if (bishoplooper(square) == "-1")
                printf("No bishop can move to %s\n", square);
            

            else if (bishoplooper(square) == "0")
                printf("Specify which bishop to move to %s\n", square);
            

            else {
                char* bishopis = bishoplooper(square);
                movepiece(bishopis, square);
            }
        }
예제 #9
0
파일: xs.c 프로젝트: aahud/harvey
int
drop(int f)
{
	if(f){
		score(5L*(rboard.max.y-pos.y)/pcsz);
		do; while(movepiece());
	}
	fusst = 0;
	rest();
	if(pos.y==rboard.min.y && !horiz())
		return 1;
	horiz();
	setpiece(0);
	pause(1500);
	choosepiece();
	lastmx = warp(mouse.xy, lastmx);
	return 0;
}
예제 #10
0
파일: chess.c 프로젝트: pkova/noobchess
    void turn (char* move) {

        int len = strlen(move);

        char square[3];
        strncpy(square, &move[len-2], 2);
        square[2] = '\0';
        memcpy(prevsquare, square, sizeof(square));
        

        int x = squarexfinder(square);
		int y = squareyfinder(square);

        if (strncmp(move, "0-0-0", 5) == 0) {

            if (cancastlelong() == 0)
                printf("Illegal move\n");

            else if (cancastlelong() == 1 && wturn == 1) {
                movepiece("e1", "c1");
                movepiece("a1", "d1");
            }

            else if (cancastlelong() == 1 && wturn == 0) {
                movepiece("e8", "c8");
                movepiece("a8", "d8");
            }

        }
       
        else if (strncmp(move, "0-0", 3) == 0) {

            if (cancastleshort() == 0)
                printf("Illegal move\n");

            else if (cancastleshort() == 1 && wturn == 1) {
                movepiece("e1", "g1");
                movepiece("h1", "f1");
            }
            
            else if (cancastleshort() == 1 && wturn == 0) {
                movepiece("e8", "g8");
                movepiece("h8", "f8");
            }

        }


        else if ((worb(map[x][y]) == 'w' && wturn == 1) || (worb(map[x][y]) == 'b' && wturn == 0))
			printf("Illegal move");
			
			
        else if (strlen(move) == 2 && move[1] == '4' && wturn == 1 && checksquare(move) == 0
                 && (board[x+1][y] == "pw" || board[x+2][y] == "pw")) {
			
            char* sqtocheck = map[x+1][y];
			bool check = checksquare(sqtocheck);

			if (check == 1) 
				movepiece(sqtocheck, move);
				
			
            else if (check == 0) {
				char* sqtocheck = map[x+2][y];
				bool check = checksquare(sqtocheck);
				
				if (check == 1) 
					movepiece(sqtocheck, move);
					

                else if (check == 0) 
					printf("Illegal move");
					
				}
			}

        else if (strlen(move) == 2 && wturn == 1 && board[x+1][y] == "pw" && board[x][y] == ". ") {
			char* from = map[x+1][y];
			movepiece(from, move);
			}

        else if (strlen(move) == 2 && move[1] == '5' && wturn == 0 && checksquare(move) == 0
                 && (board[x-1][y] == "pb" || board[x-2][y] == "pb")) {
			
            char* sqtocheck = map[x-1][y];
			bool check = checksquare(sqtocheck);

			if (check == 1) 
				movepiece(sqtocheck, move);
				
			
            else if (check == 0) {
				char* sqtocheck = map[x-2][y];
				bool check = checksquare(sqtocheck);
				
				if (check == 1) 
					movepiece(sqtocheck, move);
					

                else if (check == 0) 
					printf("Illegal move");
					
				}
			}

        else if (strlen(move) == 2 && wturn == 0 && board[x-1][y] == "pb" && board[x][y] == ". ") {
            char* from = map[x-1][y];
			movepiece(from, move);
			}


        else if (strlen(move) == 3 && move[0] == 'N' && wturn == 1)
            knightmover(square, "Nw");    

        else if (strlen(move) == 3 && move[0] == 'N' && wturn == 0) 
            knightmover(square, "Nb");

        else if (strlen(move) == 4 && move[0] == 'N' && wturn == 1 && move[1] == 'x' &&
                 board[x][y] != ". ") {

            char* status = board[x][y];

            if (status[1] == 'b')
                knightmover(square, "Nw");
            
            else
                printf("Illegal move\n");
        }

        else if (strlen(move) == 4 && move[0] == 'N' && wturn == 0 && move[1] == 'x' &&
                 board[x][y] != ". ") {

            char* status = board[x][y];

            if (status[1] == 'w')
                knightmover(square, "Nb");
            
            else
                printf("Illegal move\n");
        }

        else if (strlen(move) == 3 && move[0] == 'B' && board[x][y] == ". ")
            bishopmover(square);            

        else if (strlen(move) == 4 && move[0] == 'B' && move[1] == 'x' && board[x][y] != ". ") {

            char* status = board[x][y];

            if (wturn == 1 && status[1] == 'b')
                bishopmover(square);

            else if (wturn == 0 && status[1] == 'w')
                bishopmover(square);

            else
                printf("Illegal move\n");
        }

        else if (strlen(move) == 3 && move[0] == 'R' && board[x][y] == ". ")
            rookmover(square);

        else if (strlen(move) == 4 && move[0] == 'R' && move[1] == 'x' && board[x][y] != ". ") {

            char* status = board[x][y];

            if (wturn == 1 && status[1] == 'b')
                rookmover(square);

            else if (wturn == 0 && status[1] == 'w')
                rookmover(square);

            else
                printf("Illegal move\n");

        }
            

        else if (strlen(move) == 3 && move[0] == 'Q')
            queenmover(square);

        else if (strlen(move) == 4 && move[0] == 'Q' && move[1] == 'x' && board[x][y] != ". ") {

            char* status = board[x][y];

            if (wturn == 1 && status[1] == 'b')
                queenmover(square);

            else if (wturn == 0 && status[1] == 'w')
                queenmover(square);

            else
                printf("Illegal move\n");
        }

        else if (strlen(move) == 3 && move[0] == 'K')
            kingmover(square);

        else if (strlen(move) == 4 && move[0] == 'K' && move[1] == 'x' && board[x][y] != ". ") {

            char* status = board[x][y];

            if (wturn == 1 && status[1] == 'b')
                kingmover(square);

            else if (wturn == 0 && status[1] == 'w')
                kingmover(square);

            else
                printf("Illegal move\n");
        }

        else if (strlen(move) == 4 && wturn == 1 && move[1] == 'x' && worb(square) == 'b') {
           
            
            char str[3] = "\0";
            char m = move[0];
            str[0] = m;
            str[1] = '1';

            int column = squareyfinder(str);
            int row = x+1;


            if (row < 8 && board[row][column] == "pw")
                movepiece(map[row][column], map[x][y]);

            else
                printf("Illegal move \n");

        }
            
        else if (strlen(move) == 4 && wturn == 0 && move[1] == 'x' && worb(square) == 'w') {

            char str[3] = "\0";
            char m = move[0];
            str[0] = m;
            str[1] = '1';

            int column = squareyfinder(str);
            int row = x-1;

            if (row >= 0 && board[row][column] == "pb")
                movepiece(map[row][column], map[x][y]);

            else
                printf("Illegal move \n");

        }



        else
            printf("error");

		}
예제 #11
0
파일: xs.c 프로젝트: npe9/harvey
int
play(void)
{
    int i;
    Mouse om;
    int s;
    Rune r;
    Alt alts[NALT+1];

    alts[TIMER].c = timerc;
    alts[TIMER].v = nil;
    alts[TIMER].op = CHANRCV;
    alts[MOUSE].c = mousec;
    alts[MOUSE].v = &mouse;
    alts[MOUSE].op = CHANRCV;
    alts[SUSPEND].c = suspc;
    alts[SUSPEND].v = &s;
    alts[SUSPEND].op = CHANRCV;
    alts[RESHAPE].c = mousectl->resizec;
    alts[RESHAPE].v = nil;
    alts[RESHAPE].op = CHANRCV;
    alts[KBD].c = kbdc;
    alts[KBD].v = &r;
    alts[KBD].op = CHANRCV;
    alts[NALT].op = CHANEND;

    dt = 64;
    lastmx = -1;
    lastmx = movemouse();
    choosepiece();
    lastmx = warp(mouse.xy, lastmx);
    for(;;)
        switch(alt(alts)) {
        case MOUSE:
            if(suspended) {
                om = mouse;
                break;
            }
            if(lastmx < 0)
                lastmx = mouse.xy.x;
            if(mouse.xy.x > lastmx+DMOUSE) {
                mright();
                lastmx = mouse.xy.x;
            }
            if(mouse.xy.x < lastmx-DMOUSE) {
                mleft();
                lastmx = mouse.xy.x;
            }
            if(mouse.buttons&1 && !(om.buttons&1))
                rleft();
            if(mouse.buttons&2 && !(om.buttons&2))
                if(drop(1))
                    return 1;
            if(mouse.buttons&4 && !(om.buttons&4))
                rright();
            om = mouse;
            break;
        case SUSPEND:
            if (!suspended && s)
                suspend(1);
            else if (suspended && !s) {
                suspend(0);
                lastmx = warp(mouse.xy, lastmx);
            }
            break;
        case RESHAPE:
            redraw(1);
            break;
        case KBD:
            if(suspended)
                break;
            switch(r) {
            case 'f':
            case ';':
                mright();
                break;
            case 'a':
            case 'j':
                mleft();
                break;
            case 'd':
            case 'l':
                rright();
                break;
            case 's':
            case 'k':
                rleft();
                break;
            case ' ':
                if(drop(1))
                    return 1;
                break;
            }
            break;
        case TIMER:
            if(suspended)
                break;
            dt -= tsleep;
            if(dt < 0) {
                i = 1;
                dt = 16 * (points+nrand(10000)-5000) / 10000;
                if(dt >= 32) {
                    i += (dt-32)/16;
                    dt = 32;
                }
                dt = 52-dt;
                while(i-- > 0)
                    if(movepiece()==0 && ++fusst==40) {
                        if(drop(0))
                            return 1;
                        break;
                    }
            }
            break;
        }
}
예제 #12
0
//during the game
//when u get the coordinates of the click
void game(int x, int y){
	MEVENT ev;
	bpos *m;
	bool a;
	m=malloc(sizeof(bpos));
	int b,c,fx,fy;
	if(board[x][y]==0) {
		wrongstart();
	}
	else {
		if(turn==0) {
			if(board[x][y]<0) {
				wrongstart();
			}
		}
		else if(turn!=0){
			if(board[x][y]>0){
				wrongstart();
			}
		}
	}
	//then the user should click in the final position and we need to find the corresponding box
	c = wgetch(chessboard);
	c = wgetch(chessboard);
	wrefresh(menuwin);
	switch(c)
	{
		case KEY_MOUSE:
			if(getmouse(&ev) == OK){
				if(ev.bstate & BUTTON1_PRESSED){
					fy=ev.y;fx=ev.x;
					m=position(fx,fy);
					fy=m->col;
					fx=m->row;
					if(!((m->row+1)*(m->col+1))){
						mvwprintw(menuwin,10,10,"not valid click again ");
						wrefresh(menuwin);return;
					}
					if((turn==0)&&(board[fx][fy]<0)){
						mvwprintw(menuwin,2,6,"choose num 2 ");
					}
					else if((turn!=0)&&(board[fx][fy]>0)){
						mvwprintw(menuwin,2,6,"choose num1");
					}
					wrefresh(menuwin);
					switch(abs(board[x][y])) {
						case 9:case 10:case 11:case 12:case 13:case 14:case 15:case 16:
									b=pawn(x,y,fx,fy);
									break;
							case 2: case 7: b=horse(x,y,fx,fy);
								break;
							case 4: b=queen(x,y,fx,fy);
								break;
							case 3:case 6:b=bishop(x,y,fx,fy);
								break;
							case 1:case 8: b=rook(x,y,fx,fy);
								break;
							case 5: b=king(x,y,fx,fy);
								break;
						}
						if(b==1){
							if((turn==0)&&board[x][y]<0)
								{return;}
							else if((turn!=0)&&board[x][y]>0)
								{return;}
							if((turn==0)&&board[fx][fy]>0)
								{return;}
							else if((turn!=0)&&board[fx][fy]<0)
								{return;}
							if((board[fx][fy]>0)&&(turn!=0)){
								karr[count]=board[fx][fy];count++;printelement();
							}
							else if((board[fx][fy]<0)&&(turn==0)){
								karr[count]=board[fx][fy];count++;printelement();
							}		
							wrefresh(menuwin);move1.prevval=board[fx][fy];
							move1.newval=board[x][y];
							movepiece(x,y,fx,fy);wrefresh(menuwin);
							move1.srow=x;move1.scol=y;move1.erow=fx;move1.ecol=fy;
							push(&s,move1);
							flipturn();check();
							display_menu();
						}
				}
			}
	}
}