// read data file func getData(filename string) (ERCmin, ERCmax int, trainSet []Point) { s := util.Open(filename) util.Read(s, &ERCmin, &ERCmax) trainSet = []Point{} var p Point for util.Read(s, &p.x, &p.y) { trainSet = append(trainSet, p) } return }
// read the trail file to setup the grid func readGrid(file string) *Grid { s := util.Open(file) grid := Grid{} // first line has config params util.Read(s, &grid.steps, &grid.maxMoves) fmt.Printf("steps=%d maxMoves=%d\n", grid.steps, grid.maxMoves) // read the initial grid grid.cells = [][]Cell{} row := 0 for s.Scan() { line := s.Bytes() grid.cols = len(line) grid.cells = append(grid.cells, make([]Cell, grid.cols)) for col, cell := range line { color := -1 switch cell { case 'R', 'r': color = 0 case 'G', 'g': color = 1 case 'B', 'b': color = 2 } grid.cells[row][col].color = color if cell >= 'a' && cell <= 'z' { grid.cells[row][col].ant = true } } row++ } grid.rows = row return &grid }
// read the trail file to setup the grid func readTrail(file string) *Config { s := util.Open(file) conf := Config{grid: Grid{}} // first line has max no. of moves and plot dimensions util.Read(s, &conf.maxMoves, &conf.plotRows, &conf.plotCols) fmt.Println("max moves =", conf.maxMoves, "plot size =", conf.plotRows, conf.plotCols) // read the grid row := 0 for s.Scan() { line := s.Bytes() for col, cell := range line { switch cell { case FOOD: conf.totalFood++ case START: conf.startRow, conf.startCol = row, col conf.startDir = 1 line[col] = TRAIL } } copy := append([]byte{}, line...) conf.grid = append(conf.grid, copy) row++ } return &conf }