//public string agentMove(Kernel.Point pLoc, Kernel.Point cLoc) //{ // switch (cLoc.Column - pLoc.Column) // { // case 1: // return "Agent Moves Right"; // case -1: // return "Agent Moves Loft"; // } // switch (cLoc.Row - pLoc.Row) // { // case 1: // return "Agent Moves Up"; // case -1: // return "Agent Moves Down"; // } // return "Agent Didnt Move"; //} public override void UpdateState(BeliefState bs) { Belief = bs; int iSize = GetGridSize(); //your code here Kernel.Matrix bMatrix = new Kernel.Matrix(new Kernel.Point((byte)iSize, (byte)iSize)); delay(); int iX = 0, iY = 0; GetAgentLocation(out iX, out iY); for (int i = 1; i <= iSize; i++) { for (int j = 1; j <= iSize; j++) { if (IsLocationBlocked(i, j)) { Console.WriteLine("Blocked " + i + "," + j); // if (board.Created) board.addConsoleText("Blocked " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.LCellType.Fix); } else if (IsPossibleLocation(i, j)) { Console.WriteLine("Agent might be at " + i + "," + j); // if (board.Created) board.addConsoleText("Agent might be at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.LCellType.PAgent); } else { bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.LCellType.None); } } } Console.WriteLine("Agent at " + iX + "," + iY); // if (board.Created) board.addConsoleText(idx + ") Observation: " + obs + "\r\n Action: " + act + "\r\n Agent at: " + iX + "," + iY + "\r\n ----------------------------------------"); obs = ""; act = ""; //if (board.Created) board.addConsoleText(idx + ") " + "Observed:" + GetObservation(bs) + "\r\n Action:" + agentMove(cLoc, new Kernel.Point((byte)iY, (byte)iX)) + "\r\n(Agent at " + iX + "," + iY + ")\r\n ----------------------------------------"); //if (locFlg) { if (board.Created) board.addConsoleText(idx+ ") " + agentMove(cLoc, new Kernel.Point((byte)iY, (byte)iX)) + " (Agent at " + iX + "," + iY+ ")\r\n ----------------------------------------"); } //else //{ // locFlg = true; // if (board.Created) board.addConsoleText(idx + ") Agent at " + iX + "," + iY + "\r\n ----------------------------------------"); //} idx++; cLoc = new Kernel.Point((byte)iY, (byte)iX); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - iY), (byte)(iX - 1)), Kernel.LCellType.Agent); //if (board.Created) // { board.setMatrix(bMatrix); if (board.fF == true) { board.fF = false; board.stopSpeed(); } // } }
//public string agentMove(Kernel.Point pLoc, Kernel.Point cLoc) //{ // switch (cLoc.Column - pLoc.Column) // { // case 1: // return "Agent Moves Right"; // case -1: // return "Agent Moves Loft"; // } // switch (cLoc.Row - pLoc.Row) // { // case 1: // return "Agent Moves Up"; // case -1: // return "Agent Moves Down"; // } // return "Agent Didnt Move"; //} public override void UpdateState(BeliefState bs) { Belief = bs; int iSize = GetGridSize(); //your code here Kernel.Matrix bMatrix = new Kernel.Matrix(new Kernel.Point((byte)iSize, (byte)iSize)); delay(); int iX = 0, iY = 0; GetAgentLocation(out iX, out iY); cLoc = new Kernel.Point((byte)iY, (byte)iX); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - iY), (byte)(iX - 1)), Kernel.MCellType.Agent); for (int i = 1; i <= iSize; i++) { for (int j = 1; j <= iSize; j++) { //if (IsUnNone(i, j)) //{ // Console.WriteLine("UnNone " + i + "," + j); // // if (board.Created) board.addConsoleText("Blocked " + i + "," + j); // bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.UnNone); // bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j+1), (byte)(i - 1)), Kernel.MCellType.Pfeeling); // //bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i)), Kernel.MCellType.Pfeeling); // bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j - 1), (byte)(i - 1)), Kernel.MCellType.Pfeeling); // bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 2)), Kernel.MCellType.Pfeeling); //} if (IsPossibaleFeeling(i, j) && !((i == iX) && (j == iY))) { //Console.WriteLine("Breeze and Stench at " + i + "," + j); // if (board.Created) board.addConsoleText("Agent might be at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.Pfeeling); } if (IsUnSafe(i, j)) { //Console.WriteLine("Breeze and Stench at " + i + "," + j); // if (board.Created) board.addConsoleText("Agent might be at " + i + "," + j); if (j > i) { bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.UnNoneUp); } if (j < i) { bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.UnNoneDown); } } else if (IsSafe(i, j)) { if (i == iX && j == iY) { //Console.WriteLine("Breeze and Stench at " + i + "," + j); // if (board.Created) board.addConsoleText("Agent might be at " + i + "," + j); if (j > i) { bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.ANoneUp); } if (j < i) { bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.ANoneDown); } } else { //Console.WriteLine("Breeze and Stench at " + i + "," + j); // if (board.Created) board.addConsoleText("Agent might be at " + i + "," + j); if (j > i) { bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.NoneUp); } if (j < i) { bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.NoneDown); } } } else if ((IsFeelingBreeze(i, j)) && (IsFeelingStench(i, j))) { if (i == iX && j == iY) { //Console.WriteLine("Breeze and Stench at " + i + "," + j); //if (board.Created) board.addConsoleText("Feeling Breeze & Stench at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.AbreezeStench); } else { Console.WriteLine("Breeze and Stench at " + i + "," + j); //if (board.Created) board.addConsoleText("Feeling Breeze & Stench at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.Feeling); } } else if (IsFeelingStench(i, j)) { if (i == iX && j == iY) { //Console.WriteLine("Breeze and Stench at " + i + "," + j); //if (board.Created) board.addConsoleText("Feeling Stench at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.Astench); } else { Console.WriteLine("Stench at " + i + "," + j); //if (board.Created) board.addConsoleText("Feeling Stench at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.Stench); } } else if (IsFeelingBreeze(i, j)) { if (i == iX && j == iY) { //Console.WriteLine("Breeze and Stench at " + i + "," + j); //if (board.Created) board.addConsoleText("Feeling Breeze at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.Abreeze); } else { Console.WriteLine("Breeze at " + i + "," + j); //if (board.Created) board.addConsoleText("Feeling Breeze at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.Breeze); } } if (IsWumpus(i, j) && (IsPit(i, j))) { Console.WriteLine("wumpus & pit at " + i + "," + j); //if (board.Created) board.addConsoleText("Wumpus & Pit at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.WumpusPit); } else if (IsWumpus(i, j)) { Console.WriteLine("wumpus at " + i + "," + j); //if (board.Created) board.addConsoleText("wumpus at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.Wumpus); } else if (IsPit(i, j)) { Console.WriteLine("pit at " + i + "," + j); //if (board.Created) board.addConsoleText("Pit at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.Pit); } if (IsCrown(i, j)) { if (i == iX && j == iY) { //Console.WriteLine("Breeze and Stench at " + i + "," + j); // if (board.Created) board.addConsoleText("Agent might be at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.Acrown); } else { Console.WriteLine("gold at " + i + "," + j); //if (board.Created) board.addConsoleText("Gold at at " + i + "," + j); bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.MCellType.Crown); } } //else bMatrix.addCellValue(new Kernel.Point((byte)(iSize - j), (byte)(i - 1)), Kernel.LCellType.None); } } Console.WriteLine("Agent at " + iX + "," + iY); //if (board.Created) board.addConsoleText(idx + ") Observation: " + obs + "\r\n Action: " + act + "\r\n Agent at: " + iX + "," + iY + "\r\n ----------------------------------------"); obs = ""; act = ""; //if (board.Created) board.addConsoleText(idx + ") " +(GetObservation()!=""?"Observed:\r\n"+GetObservation():"No Observation\r\n") +"Action:\r\n"+ agentMove(cLoc, new Kernel.Point((byte)iY, (byte)iX)) + " (Agent at " + iX + "," + iY + ")\r\n ----------------------------------------"); //if (locFlg) { if (board.Created) board.addConsoleText(idx+ ") " + agentMove(cLoc, new Kernel.Point((byte)iY, (byte)iX)) + " (Agent at " + iX + "," + iY+ ")\r\n ----------------------------------------"); } //else //{ // locFlg = true; // if (board.Created) board.addConsoleText(idx + ") Agent at " + iX + "," + iY + "\r\n ----------------------------------------"); //} idx++; //if (board.Created) //{ board.setMatrix(bMatrix); if (board.fF == true) { board.fF = false; board.stopSpeed(); } // } }