示例#1
0
void Column::drawChips(){
    short blockHeight = size.GetHeight() / NUM_SLOTS;   // Get height of slot.
    for(short i=0; i < NUM_SLOTS; ++i){
        if (slots[i] != none){  // To draw game chips, where
            Chip chip(wxPoint(position.x, i * blockHeight));
            chip.draw(Chip::ChipColor(slots[i]));
        }
        else
            i=NUM_SLOTS;    // Break cycle.
    }
}
示例#2
0
void	avm(char *file)
{
  try
    {
      Io	IO(file);
      std::list<std::string> listf = IO.getList();
      Chipset chip(listf);
      std::list<std::string> instru = chip.getInstruct();
      Cpu cpu(instru);
    }
  catch (const std::exception & e ) { std::cerr << e.what();}
}
示例#3
0
/* ---- void HexGameIO::Prompt(HexColor turn); --------------------------------
        Prompt player for move
   ---------------------------------------------------------------------------- */
void HexGameIO::Prompt(HexColor turn)
{
    if ((turn != HEXBLUE) && (turn != HEXRED))
        throw HEXGAME_ERR_INVALIDTURN;
     
    std::string sDirection;
    
    if (turn == HEXBLUE)
        sDirection = "BOTTOM -> TOP";
    else
        sDirection = "LEFT -> RIGHT";
    
    std::cout << "\n" << name(turn) << " PLAYER (" << chip(turn) << "), your turn!\n"
              << "You move " << sDirection << "\n"
              << "Please enter your move ROW COL: ";
    
}   
示例#4
0
  /**
   * Walk the pattern chip through the search chip to find the best interest
   *  
   * @param cube [in] The Isis::Cube to look for an interesting area in 
   * @param sample [in] The sample postion in the cube where the chip is located
   * @param line [in] The line postion in the cube where the chip is located 
   *  
   * @return  Returns the status of the operation.  The following conditions can 
   *          occur true=Success, false=Failed
   */
  bool InterestOperator::Operate(Cube &cube, int sample, int line) {
    int pad = Padding();
    Chip chip(2*p_deltaSamp + p_samples + pad, 2*p_deltaLine + p_lines + pad);
    chip.TackCube(sample, line);
    if (p_clipPolygon != NULL) chip.SetClipPolygon(*p_clipPolygon);
    chip.Load(cube);
    // Walk the search chip and find the best interest
    int bestSamp = 0;
    int bestLine = 0;
    double smallestDist = DBL_MAX;
    double bestInterest = Isis::Null;
    for (int lin=p_lines/2 + 1; lin<=2*p_deltaLine+p_lines/2 + 1; lin++) {
      for (int samp=p_samples/2 + 1; samp<=2*p_deltaSamp+p_samples/2 + 1; samp++) {
        Chip subChip = chip.Extract(p_samples+pad, p_lines+pad, samp, lin);
        double interest = Interest(subChip);
        if (interest != Isis::Null) {
          if ((bestInterest == Isis::Null) || CompareInterests(interest,bestInterest)) {
            double dist = std::sqrt(std::pow(sample-samp,2.0)+std::pow(line-lin,2.0));
            if (interest == bestInterest && dist>smallestDist) {
              continue;
            } else {
              bestInterest = interest;
              bestSamp = samp;
              bestLine = lin;
              smallestDist = dist;
            }
          }
        }
      }
    }

    // Check to see if we went through the interest chip and never got a interest at
    // any location.
    if (bestInterest == Isis::Null || bestInterest<p_minimumInterest) return false;

    p_interestAmount = bestInterest;
    chip.SetChipPosition(bestSamp, bestLine);
    p_cubeSample = chip.CubeSample();
    p_cubeLine   = chip.CubeLine();
    return true;
  }
示例#5
0
int load_config_file(const char *config)
{
	int rc = -1, line_index = 0;
    FILE* f;
	char line[256];
    chip_family* family = NULL;
    char* name;
    char* param;
    int argc;
    char** argv = NULL;
    int id, mask;
    int ir_length;

	f = fopen(config, "rt");
	if (f == NULL)
	{
        msgf(STR_FAILED_TO_OPEN_CONFIG_FILE);
		return -1;
	}

	for (line_index = 1; !feof(f); line_index++)
	{
		if (fgets(line, sizeof(line), f) == NULL)
			break;

        strip_whitespaces(line);

        // Empty
        if (*line == 0)
            continue;

        // Comment
        if (line[0] == ';' || line[0] == '#')
            continue;

        if (strcasecmp(line, "BEGIN_FAMILY") == 0)
        {
            if (family != NULL)
                goto cleanup;
            family = new chip_family;
            if (family == NULL)
                goto cleanup;
        }
        else
        if (strcasecmp(line, "END_FAMILY") == 0)
        {
            if (family == NULL)
                goto cleanup;

            // Check if NAME, DESC, TYPE exist
            if (family->vars.exists(strNAME) < 0)
                goto cleanup;
            if (family->vars.exists(strDESC) < 0)
                goto cleanup;
            if (family->vars.exists(strTYPE) < 0)
                goto cleanup;

            // Add family to chip database
            g.chips.push_back(family);
            family = NULL;
        }
        else
        {
            name = line;
            param = strchr(line, '=');
            *param = 0;
            param++;

            strip_whitespaces(name);
            strip_whitespaces(param);

            if (*name == 0)
                goto cleanup;

            parse_cmdline_args(param, &argc, &argv);
    
            if (family)
            {
                if (strcasecmp(name, "CHIP") == 0)
                {
                    if (argc != 4)
                        goto cleanup;

                    if (str2num(argv[1], &id) ||
                        str2num(argv[2], &mask) ||
                        str2num(argv[3], &ir_length))
                        goto cleanup;
                    
                    family->push_back(chip(argv[0], id, mask, ir_length, family));
                }
                else
                if (argc > 0)
                    family->vars.add(name, argv[0]);
            }
            else
				g.vars.add(name, param);

            free(argv);
            argv = NULL;
        }
	}
    
    rc = 0;
	
cleanup:

	if (f)
		fclose(f);

    if (family)
        delete family;

    if (argv)
        free(argv);

    if (rc)
        msgf(STR_INVALID_CONFIG_FILE, line_index);

	return rc;
}
示例#6
0
/* ---- void HexGameIO::PrintBoard(HexBoard &board); --------------------------
        Prints board
   ---------------------------------------------------------------------------- */
void HexGameIO::PrintBoard(HexBoard &board)
{
    int size = board.Size();
    char sMargin[] = "    ";
    
    // ----- print column labels ----------------------------------------------
    std::cout << sMargin;
    
    for (int i = 0; i < (3 + 1); i++)
        std::cout << " ";    
        
    int padding = (size * 3 - 9) / 2;
    
    for (int i = 0; i < padding; i++)
        std::cout << " ";
        
    std::cout << name(HEXBLUE) << " GOAL" << "\n";
    
    
    std::cout << sMargin;
    
    for (int i = 0; i < (3 + 1); i++)
        std::cout << " ";    
        
    for (int i = 0; i < size; i++)
        std::cout << " " << i << " ";
        
    std::cout << "\n";
    
    
    // ----- print top border -------------------------------------------------
    std::cout << sMargin;
    
    for (int i = 0; i < (3 + 1); i++)
        std::cout << " ";        
        
    for (int i = 0; i < (2 + 3 * size + 1); i++)
        std::cout << "-";        
        
    std::cout << "\n";
    
    // ----- row labels, lateral borders and cells ----------------------------
    for (int row = 0; row < size; row++)
    {
        if (row == (size/2 - 1))
            std::cout << " " << name(HEXRED);
        else if (row == (size/2))
            std::cout << "HOME";
        else if (row == (size/2 + 1))
            std::cout << " (" << chip(HEXRED) << ")";
        else
            std::cout << sMargin;
            
        for (int s = 0; s < row; s++)
            std::cout << " ";
            
        std::cout << ((row < 10) ? "  " : " ") << row << " " << "\\ ";
        
        for (int col = 0; col < size; col++)
            std::cout << " " << chip(board.GetColor(row, col)) << " ";
            
        std::cout << " \\ " << row << " ";
        
        if (row == (size/2 - 1))
            std::cout << name(HEXRED);
        else if (row == (size/2))
            std::cout << "GOAL";
        
        std::cout << "\n";
    }
    
    // ----- print bottom border ----------------------------------------------
    std::cout << sMargin;
    
    for (int i = 0; i < (size + 3 + 1); i++)
        std::cout << " ";
        
    for (int i = 0; i < (2 + 3 * size + 1); i++)
        std::cout << "-";
        
    std::cout << "\n";   

    // ----- print column labels ----------------------------------------------
    std::cout << sMargin;
    
    for (int i = 0; i < (size + 3 + 1 + 2); i++)
        std::cout << " ";
        
    for (int i = 0; i < size; i++)
        std::cout << " " << i << " ";
        
    std::cout << "\n";
    
    for (int i = 0; i < (size + 3 + 1 + 2); i++)
        std::cout << " ";
        
    for (int i = 0; i < padding; i++)
        std::cout << " ";
        
    std::cout << name(HEXBLUE) << " HOME (" << chip(HEXBLUE) <<")\n\n";
}