public CompoundTerm DoAction(CompoundTerm action) { switch (action.Name) { case ("Tests"): return(null); // first action in test seq. case ("ServerSocket"): s.Socket(); return(null); case ("ServerBind"): s.Bind(host, port); return(null); case ("ServerListen"): s.Listen(); return(null); case ("ServerAccept"): s.Accept(); return(null); case ("ServerReceive"): s.Receive(); return(null); case ("ServerSend"): // s.Send sends a double, not a string! s.Send((double)((Literal)action.Arguments[0]).Value); return(null); case ("ServerCloseConnection"): s.CloseConnection(); return(null); case ("ServerClose"): s.Close(); return(null); case ("ClientSocket"): c.Socket(); return(null); case ("ClientConnect"): c.Connect(host, port); return(null); case ("ClientSend"): c.Send("T"); return(null); case ("ClientReceive_Start"): // c.Receive returns a double, not a string return(CompoundTerm.Create("ClientReceive_Finish", c.Receive())); case ("ClientClose"): c.Close(); return(null); default: throw new Exception("Unexpected action " + action); } }
public CompoundTerm Recharge(int id) { if (aliveRobots.Contains(id)) { power[id] = power[id] + 1.0; reward[id] = reward[id] - 1.5; Random r = new Random(); if (r.Next(0, 2) == 0) { return(new CompoundTerm(Symbol.Parse("Recharge"), CompoundTerm.Create("Robot", id))); } } return(null); }
public CompoundTerm DoAction(CompoundTerm action) { switch (action.FunctionSymbol.ToString()) { case "Setup_Start": lock (this) { Global.Setup(); return(CompoundTerm.Create("Setup_Finish")); } case "Create": lock (this) //avoid simultaneous creation of clients { //System.Diagnostics.Debugger.Break(); //System.Windows.Forms.MessageBox.Show("Going to create client " + action.Arguments[0].ToString());//??? clients[action.Arguments[0].ToString()] = Global.CreateClient(action.Arguments[0].ToString()); // //System.Windows.Forms.MessageBox.Show("Created client " + action.Arguments[0].ToString());//??? } return(null); case "Enter": lock (this) //avoid simultaneous entering of clients { Global.Enter(clients[action.Arguments[0].ToString()]); } return(null); case "Exit": lock (this) { Global.Exit(clients[action.Arguments[0].ToString()]); } return(null); case "Send": lock (this) { string message = (string)((Literal)action.Arguments[1]).Value; clients[action.Arguments[0].ToString()].PostMessage(message); } return(null); default: throw new Exception("Unexpected action: " + action); } }
/// <summary> /// Perform the action /// </summary> /// <param name="action">the given action</param> /// <returns>the returned action (or null)</returns> public CompoundTerm DoAction(CompoundTerm action) { switch (action.FunctionSymbol.ToString()) { case "SetPlayer1": wh.Set(); // Signal the waiting thread to proceed (test-cases continue, don't exit) Console.WriteLine("\nSetting Player1 to " + (string)action[0]); runner.setPlayer("Player1", (string)action[0]); return(null); case "SetPlayer2": Console.WriteLine("\nSetting Player2 to " + (string)action[0]); runner.setPlayer("Player2", (string)action[0]); return(null); case "ReadLastResult_Start": Console.WriteLine("\nChecking the results list-box"); Thread.Sleep(200); return(CompoundTerm.Create("ReadLastResult_Finish", runner.getLastResult())); default: throw new InvalidOperationException("Unrecognized action: " + action.ToString()); } }