📄 zone.cc
字号:
/* YAKS, a Khepera simulator including a separate GA and ANN (Genetic Algoritm, Artificial Neural Net). Copyright (C) 2000 Johan Carlsson (johanc@ida.his.se) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#include "zone.h"/** * Constructor for Zone, creates a new zone. * @param fp A file descriptor open for reading which contains the data for the new zone. */Zone::Zone(FILE *fp){ fscanf(fp,"zone %f %f %f\n", &x, &y, &r); visit = (int*) malloc(sizeof(int)*paramNrOfRobots); clearVisit();}/** * Constructor for Zone, creates a new zone. * @param str A string which contains the data for the new zone. */Zone::Zone(char *str){ sscanf(str,"zone %f %f %f\n", &x, &y, &r); visit = (int*) malloc(sizeof(int)*paramNrOfRobots); clearVisit();}/** * Deconstructor for Zone. Deallocates allocated memory. * */Zone::~Zone(){ free(visit);}/** * Check if a robot is in the zone, keeps an internal count of the number of visits. * @param xp The \a x coordinate of the circles center. * @param yp The \a y coordinate of the circles center. * @param robotNr Which robot that we checks if it visited the zone. * @return 1 if the robot is in the zone else 0. * @see clearVisit * @see visits */int Zone::inZone(float xp, float yp, int robotNr){ if(g_distPoint(xp,yp,x,y)<r){ visit[robotNr]++; return 1; } else{ return 0; }}/** * Clear the internal record of robots visitation. * @see visits * @see inZone */void Zone::clearVisit(){ for(int i=0; i < paramNrOfRobots; i++){ visit[i] = 0; }}/** * Get the number of visits a robot has done in a zone. * @param robotNr Which robot. * @return The number of visits. * @todo Fix so that the number of visits only increases when a robot makes a new visit. For now each timestep will result in a new visit if the robot hasent left since it's last visit. * @see clearVisit * @see inZone */int Zone::visits(int robotNr){ return visit[robotNr];}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -