Example #1
0
static RET_CODE on_othello_board_select(control_t *p_ctrl, u16 msg,
  u32 para1, u32 para2)
{
  BOOL ret;
  
  if (do_move_chess(&chess_board,
                    (u16)((cur_row + 1) * 10 + (cur_col + 1)),
                    (u8)(~computer_side & 3), callback))
  {
    othello_game = OTHELLO_HAPPY;
    get_chess_score(&chess_board, &WhitePoint, &BlackPoint);
    othello_update_status();
    othello_draw_background(FALSE);
    /* computer round */
    ret = computer_play(&chess_board, callback);
    get_chess_score(&chess_board, &WhitePoint, &BlackPoint);
    othello_update_status();
    othello_draw_background(FALSE);
    
    if(!ret)
    {
      game_over(&chess_board, callback);
    }
  }  

  return SUCCESS;
}
Example #2
0
BOOL computer_play(board_type *board_ptr, othello_callback callback)
{
    tree_node_type node;
    u16 affected_list[MAX_AFFECTED_PIECES];

    cur_depth =0;

start:

    memcpy(&node.board, board_ptr, sizeof(board_type));
    node.movepos =0;

    if(cur_step>= STEP_MONMENT2)
    {
        extend_node_two(&node, NULL, computer_side);
    }
    else if(cur_step > STEP_MONMENT1)
    {
        max_depth = depth2[g_iGameLevel];
        extend_node_one(&node, NULL, computer_side);
    }
    else
    {
        max_depth = depth1[g_iGameLevel];
        extend_node_one(&node, NULL, computer_side);
    }

    if(!do_move_chess(board_ptr, node.movepos, computer_side, callback))
    {
        if(!find_move(board_ptr, 11, (u8)((~computer_side)&0x03), affected_list))
        {
            return FALSE;//game over
        }
        else
        {
            callback(COMPUTER_NO_STEP, 0, 0);
            return TRUE;
        }
    }
    else
    {
        if(!find_move(board_ptr, 11, (u8)((~computer_side)&0x03), affected_list))
        {
            if(!find_move(board_ptr, 11, computer_side, affected_list))
            {
                return FALSE;//game over
            }
            else
            {
                callback(USER_NO_STEP, 0, 0);

                goto start;
            }
        }
    }

    return TRUE;
}
Example #3
0
static PRESULT othello_key_proc(UINT32 vkey, UINT8 key_repeat_cnt, UINT8 key_status)
{
	PRESULT ret = PROC_LOOP;
	UINT8 back_saved;
	if (key_status == PAN_KEY_PRESSED)
	{
		switch (vkey)
		{
			case V_KEY_UP:
			case V_KEY_DOWN:
			case V_KEY_LEFT:
			case V_KEY_RIGHT:
				draw_cursor(cur_row, cur_col, WSTL_GAME_BACKGROUND_IDX);
				if (vkey == V_KEY_UP)
				{
					cur_row = cur_row == 0 ? 7 : cur_row - 1;
				}
				else if (vkey == V_KEY_DOWN)
				{
					cur_row = cur_row == 7 ? 0 : cur_row + 1;
				}
				else if (vkey == V_KEY_LEFT)
				{
					cur_col = cur_col == 0 ? 7 : cur_col - 1;
				}
				else if (vkey == V_KEY_RIGHT)
				{
					cur_col = cur_col == 7 ? 0 : cur_col + 1;
				}
				draw_cursor(cur_row, cur_col, WSTL_GAME_CURSOR_IDX);
				break;

			case V_KEY_ENTER:
				if (do_move_chess(&chess_board, (cur_row + 1) *10+(cur_col + 1), ~computer_side &3, callback))
				{
					draw_cursor(cur_row, cur_col, WSTL_GAME_BACKGROUND_IDX);

					get_chess_score(&chess_board, &WhitePoint, &BlackPoint);
					update_status(Class, BlackPoint, WhitePoint);

					/* computer round */
					computer_play(&chess_board, callback);

					get_chess_score(&chess_board, &WhitePoint, &BlackPoint);
					update_status(Class, BlackPoint, WhitePoint);

					draw_cursor(cur_row, cur_col, WSTL_GAME_CURSOR_IDX);
				}
				break;

			case V_KEY_MENU:
			case V_KEY_EXIT:
				win_compopup_init(WIN_POPUP_TYPE_OKNO);
				win_compopup_set_frame(GAME_MSG_LEFT, GAME_MSG_TOP, GAME_MSG_WIDTH, GAME_MSG_HEIGHT);
				win_compopup_set_msg_ext(NULL, NULL, RS_GAME_MSG_DO_YOU_QUIT);
				if (win_compopup_open_ext(&back_saved) == WIN_POP_CHOICE_YES)
				{
					othello_init();
                    OSD_ObjOpen((POBJECT_HEAD)&game_con, 0xFFFFFFFF) ;  
					/*othello_init();
					othello_draw_background();
					update_status(Class, BlackPoint, WhitePoint,TRUE);
					OSD_SetAttr((POBJECT_HEAD) &txt_start, C_ATTR_ACTIVE);
					OSD_ChangeFocus((POBJECT_HEAD) &game_con, 1,  \
						C_UPDATE_FOCUS | C_DRAW_SIGN_EVN_FLG);*/
				}
				break;
			default:
				ret = PROC_PASS;
				break;
		}
	}

	return ret;
}