//  calculate score according to possible moves and win chance.
int MinMaxPlayer::getMinMaxScore(Board const& board, Field current_field, Position possible_move) {
    
    int x = possible_move.getX();
    int y = possible_move.getY();
    int ver_score = 0;
    int hor_score = 0;
    int dia1_score = 0;
    int dia2_score = 0;
    
    //check horizontal:
    for (int temp_x = 0; temp_x<3; temp_x++) {
        //check if the evaluated field is not the current field and go
        if (temp_x != x) {
            hor_score += CheckField(board, current_field, temp_x, y);
        }
    }
    
    //check horizontal:
    for (int temp_y = 0; temp_y<3; temp_y++) {
        //check if the evaluated field is not the current field and go
        if (temp_y != y) {
            ver_score += CheckField(board, current_field, x, temp_y);
        }
    }
    
    //check diagonal
    // the modulos work as follows: we are always in a diagonal segment when the values are equal, or if there is a 0 and a 2.
    if (y == x) {
        for (int i = 0; i<3; i++) {
            if (i != x && i != y) {
                dia1_score += CheckField(board, current_field, i, i);
            }
        }
    }
    
    if (y%2 == x || x%2 == y || x == y) {
        //a diagonal check is needed;
        for (int i = 0; i<3; i++) {
            if (i != x && 2-i != y) {
                dia2_score += CheckField(board, current_field, i, 2-i);
            }
        }
    }
    
    //compare all scores
    int scores[] ={ver_score, hor_score, dia1_score, dia2_score};
    int highest_score = 0;
    
    for (int score : scores) {
        if (score > highest_score) {
            highest_score = score;
        }
    }

    return highest_score;
    
}
Exemplo n.º 2
0
void Field::EndSwapCallback(Event *ev)
{
	if (CheckField())
	{
		state = fsAnimation;		
	}
	else
	{
		if (!BackSwap()) state = fsWaiting;
	}
}
Exemplo n.º 3
0
void ReadItem(string& tReader, const TCHAR* sTitle, bool bCanEmpty,
              const string& tDefault, FIELD_CHECKER_STRING pFunFieldChecker)
{
    SetItemTitle(sTitle);
    string sValue = g_pTabFile->GetString(g_iLine, sTitle);
    size_t l = sValue.size();
    if(l > 1 && sValue[0] == '"' && sValue[l - 1] == '"') sValue = sValue.substr(1, l - 2);
    trimend(sValue);
    CheckEmpty(tReader, sValue, bCanEmpty, tDefault);
    if(!sValue.empty())
    {
        SetValue(tReader, sValue);
    }
    CheckField(tReader, pFunFieldChecker);
}
Exemplo n.º 4
0
void ReadItem(uint32& tReader, const TCHAR* sTitle, bool bCanEmpty,
              uint32 tDefault, FIELD_CHECKER pFunFieldChecker, uint32 fFieldCheckerParam)
{
    SetItemTitle(sTitle);
    string sValue = g_pTabFile->GetString(g_iLine, sTitle);
    CheckEmpty(tReader, sValue, bCanEmpty, tDefault);
    if(!sValue.empty())
    {
        int32 tTempReader;
        SetValue(tTempReader, sValue);
        CheckUIntType(tTempReader);
        tReader = tTempReader;
    }
    CheckField(tReader, pFunFieldChecker, fFieldCheckerParam);
}
Exemplo n.º 5
0
void Field::DropEndCallback(Event *ev)
{
	safeSpCast<Jewel>(ev->target)->setState(jsNormal);
	droped_count--;
	if (droped_count==0) 
	{
		if (CheckField()) 
			DropField();
		else
		{
			if (FindSolutions())
				state = fsWaiting;
			else 
				RefreshField();
		}
	}
}
Exemplo n.º 6
0
void ReadItem(CCfgCalc*& tReader, const TCHAR* sTitle, bool bCanEmpty,
              float tDefault, FIELD_CHECKER pFunFieldChecker, float fFieldCheckerParam)
{
    SetItemTitle(sTitle);
    string sValue = g_pTabFile->GetString(g_iLine, sTitle);
    trimend(sValue);
    CheckEmpty(tReader, sValue, bCanEmpty, tDefault);
    if(!sValue.empty())
    {
        SetValue(tReader, sValue);
    }
    if(pFunFieldChecker && tReader->IsSingleNumber())
    {
        float fTemp = float(tReader->GetDblValue());
        CheckField(fTemp, pFunFieldChecker, fFieldCheckerParam);
    }
}