public Bot(int x, int y, Bot parentBot) { point = new MPoint(x, y); //DEBUG //courseOrientation = OrientationType.TOP; courseOrientation = (OrientationType)MRandom.Next(Enum.GetValues(typeof(OrientationType)).Length); health = Const.BOT_HEALTH_BIRTH; iteration = 0; age = (parentBot != null ? parentBot.age + 1 : 1); generateProgram(parentBot); dieByToxin = false; return; }
public override bool Equals(object obj) { MPoint p = (MPoint)obj; return(p.x == x && p.y == y); }
private int doCommand() { int step = 1; byte command = program[address]; cmd_calls[address] = cmd_calls[address] + 1; if (command < 24) { Cell currentCell = Grid.CurrentGrid.cells[point.x, point.y]; MPoint targetPoint = point + Const.ORIENTATIONS[((int)courseOrientation + (command % 8)) % 8]; Cell targetCell = Grid.CurrentGrid.cells[targetPoint.x, targetPoint.y]; address += (byte)targetCell.content; if (command < 8) { // // ШАГНУТЬ // /* * if (targetCell.content == CellContentType.BOT) { } * if (targetCell.content == CellContentType.EMPTY) { } * if (targetCell.content == CellContentType.FOOD) { } * if (targetCell.content == CellContentType.TOXIN) { } * if (targetCell.content == CellContentType.WALL) { } */ if (targetCell.content == CellContentType.EMPTY) { point = targetPoint; currentCell.Clear(); targetCell.Clear(); targetCell.SetContent(CellContentType.BOT); } else if (targetCell.content == CellContentType.FOOD) { health = Math.Min(health + Const.BOT_HEALTH_FOOD, Const.BOT_HEALTH_MAX); Grid.CurrentGrid.generation.CreateFoodToxin(1); point = targetPoint; currentCell.Clear(); targetCell.Clear(); targetCell.SetContent(CellContentType.BOT); } else if (targetCell.content == CellContentType.TOXIN) { health = 0; dieByToxin = true; Grid.CurrentGrid.generation.CreateFoodToxin(1); point = targetPoint; currentCell.Clear(); targetCell.Clear(); targetCell.SetContent(CellContentType.BOT); } step = Const.BOT_PROGRAM_STEP_MAX; } else if (command < 16) { // // ВЗЯТЬ ЕДУ / ПРЕОБРАЗОВАТЬ ЯД // /* * if (targetCell.content == CellContentType.BOT) { } * if (targetCell.content == CellContentType.EMPTY) { } * if (targetCell.content == CellContentType.FOOD) { } * if (targetCell.content == CellContentType.TOXIN) { } * if (targetCell.content == CellContentType.WALL) { } */ if (targetCell.content == CellContentType.FOOD) { health = Math.Min(health + Const.BOT_HEALTH_FOOD, Const.BOT_HEALTH_MAX); targetCell.Clear(); Grid.CurrentGrid.generation.CreateFoodToxin(1); } else if (targetCell.content == CellContentType.TOXIN) { targetCell.Clear(); targetCell.SetContent(CellContentType.FOOD); } step = Const.BOT_PROGRAM_STEP_MAX; } else if (command < 24) { // // ПОСМОТРЕТЬ // /* * if (targetCell.content == CellContentType.BOT) { } * if (targetCell.content == CellContentType.EMPTY) { } * if (targetCell.content == CellContentType.FOOD) { } * if (targetCell.content == CellContentType.TOXIN) { } * if (targetCell.content == CellContentType.WALL) { } */ } } else if (command < 32) { // // ПОВЕРНУТЬСЯ // address += 1; /* * if (targetCell.content == CellContentType.BOT) { } * if (targetCell.content == CellContentType.EMPTY) { } * if (targetCell.content == CellContentType.FOOD) { } * if (targetCell.content == CellContentType.TOXIN) { } * if (targetCell.content == CellContentType.WALL) { } */ courseOrientation = (OrientationType)(((int)courseOrientation + (command % 8)) % 8); } else { // // БЕЗУСЛОВНЫЙ ПЕРЕХОД в ПРОГРАММЕ // address += command; //address += (byte)(command - 31); //address += (byte)(command - 31 + 6); } address = (byte)(address % Const.BOT_PROGRAM_SIZE); return(step); }
//private Bot bot; public Cell(int x, int y) { point = new MPoint(x, y); content = CellContentType.EMPTY; //bot = null; }