示例#1
0
bool winnerTest(int player){ //return true on 'player' win
int i;
	for(i = 0; i < NUMCOL; i++){
		if(testCol(i,player)) {
			return 1;
		}
	}
	for(i = 0; i < NUMROW; i++){
		if(testRow(i,player)) {
			return 1;
		}
	}
	if(testDiagUp(player)) {
		return 1;
	}
	if(testDiagDown(player)) {
		return 1;
	}
return 0;
}
示例#2
0
  //----------------------------------------------------------------------
  void CondProbTableTest::testTable(const string& testName, CondProbTable& table, 
                                    const vector<vector<Real> > & rows)
  {
  
    // Test the numRows(), numCols() calls
    TESTEQUAL(numRows(), table.numRows());
    TESTEQUAL(numCols(), table.numColumns());

    // See if they got added right
    vector<Real>  testRow(numCols());
    for (Size i=0; i<numRows(); i++) {
      stringstream ss;
      ss << "updateRow " << i;
    
      table.getRow((UInt)i, testRow);
      testVectors(testName+ss.str(), rows[i], testRow);
    }


    // --------------------------------------------------------------------
    // Try out normal inference
    vector<Real> expValue;
    vector<Real> output(numRows());
  
    // Row 0 matches row 3, so we get half and half hits on those rows
    table.inferRow (rows[0], output, CondProbTable::inferMarginal);
    testVectors(testName+"row 0 infer", makeCol((Real).16, (Real)0, (Real)0, (Real).24), output);
  
    // Row 1 matches only row 1
    table.inferRow (rows[1], output, CondProbTable::inferMarginal);
    testVectors(testName+"row 1 infer", makeCol((Real)0, 1, (Real)0, (Real)0), output);

    // Row 2 matches only row 2 and 3
    table.inferRow (rows[2], output, CondProbTable::inferMarginal);
    testVectors(testName+"row 2 infer", makeCol((Real)0, (Real)0, (Real).36, (Real).24), output);

    // Row 3 matches row 0 & row 2 halfway, and row 3 exactly
    table.inferRow (rows[3], output, CondProbTable::inferMarginal);
    testVectors(testName+"row 3 infer", makeCol((Real).24, (Real)0, (Real).24, (Real).52), output);
  
  
    // --------------------------------------------------------------------
    // Try out inferEvidence inference
  
    // Row 0 matches row 0 and half row 3, so we get half and half hits on those rows
    table.inferRow (rows[0], output, CondProbTable::inferRowEvidence);
    testVectors(testName+"row 0 inferEvidence", makeCol((Real).4, (Real)0, (Real)0, (Real).24), output);
  
    // Row 1 matches only row 1
    table.inferRow (rows[1], output, CondProbTable::inferRowEvidence);
    testVectors(testName+"row 1 inferEvidence", makeCol((Real)0, 1, (Real)0, (Real)0), output);

    // Row 2 matches only row 2 and half row 3
    table.inferRow (rows[2], output, CondProbTable::inferRowEvidence);
    testVectors(testName+"row 2 inferEvidence", makeCol((Real)0, (Real)0, (Real).6, (Real).24), output);

    // Row 3 matches row 0 & row 2 halfway, and row 3 exactly
    table.inferRow (rows[3], output, CondProbTable::inferRowEvidence);
    testVectors(testName+"row 3 inferEvidence", makeCol((Real).6, (Real)0, (Real).4, (Real).52), output);
  
  
    // --------------------------------------------------------------------
    // Try out inferMaxProd inference
  
    // Row 0 matches row 0 and half row 3, so we get half and half hits on those rows
    table.inferRow (rows[0], output, CondProbTable::inferMaxProd);
    testVectors(testName+"row 0 inferMaxProd", makeCol((Real).16, (Real)0, (Real)0, (Real).24), output);
  
    // Row 1 matches only row 1
    table.inferRow (rows[1], output, CondProbTable::inferMaxProd);
    testVectors(testName+"row 1 inferMaxProd", makeCol((Real)0, 1, (Real)0, (Real)0), output);

    // Row 2 matches only row 2 and half row 3
    table.inferRow (rows[2], output, CondProbTable::inferMaxProd);
    testVectors(testName+"row 2 inferMaxProd", makeCol((Real)0, (Real)0, (Real).36, (Real).24), output);

    // Row 3 matches row 0 & row 2 halfway, and row 3 exactly
    table.inferRow (rows[3], output, CondProbTable::inferMaxProd);
    testVectors(testName+"row 3 inferMaxProd", makeCol((Real).24, (Real)0, (Real).24, (Real).36), output);
  
  
    // --------------------------------------------------------------------
    // Try out inferViterbi inference
  
    // Row 0 matches row 0 and half row 3, so we get half and half hits on those rows
    table.inferRow (rows[0], output, CondProbTable::inferViterbi);
    testVectors(testName+"row 0 inferViterbi", makeCol((Real)0, (Real)0, (Real)0, (Real).4), output);
  
    // Row 1 matches only row 1
    table.inferRow (rows[1], output, CondProbTable::inferViterbi);
    testVectors(testName+"row 1 inferViterbi", makeCol((Real)0, 1, (Real)0, (Real)0), output);

    // Row 2 matches only row 2 and half row 3
    table.inferRow (rows[2], output, CondProbTable::inferViterbi);
    testVectors(testName+"row 2 inferViterbi", makeCol((Real)0, (Real)0, (Real).6, (Real)0), output);

    // Row 3 matches row 0 & row 2 halfway, and row 3 exactly
    table.inferRow (rows[3], output, CondProbTable::inferViterbi);
    testVectors(testName+"row 3 inferViterbi", makeCol((Real)0, (Real)0, (Real).4, (Real).6), output);
  
  
    // Add a row a second time, the row should double in value
    table.updateRow(0, rows[0]);
    expValue = rows[0];
    for (Size i=0; i<numCols(); i++)
      expValue[i] *= 2;
    table.getRow(0, testRow);
    testVectors(testName+"row 0 update#2", expValue, testRow);
  
  }