private void CreateTrainingData() { DecisionTree.TrainingExample[] examples = new DecisionTree.TrainingExample[FeatureList.Count]; for (int i = 0; i < FeatureList.Count; i++) { examples[i] = (new DecisionTree.TrainingExample(FeatureList[i], ActionsAsStates[actionHightlights[i]])); } AIWrapper.CreateTree(examples); }
private void button_test_Click(object sender, EventArgs e) { chart_test_total.Series[0].Points.Clear(); listview_test.Items.Clear(); int total = int.Parse(textbox_testcount.Text), correct = 0; AIWrapper wrapper = new AIWrapper(textbox_exepath.Text); wrapper.SetNetwork(textbox_networkpath.Text); wrapper.SetWeight(textbox_biasweightpath.Text); test_res = wrapper.Predict(dataPath, int.Parse(textbox_dataoffset.Text), dataWidth * dataWidth, total); int i, j = 0, result, answer; foreach (List <float> lf in test_res) { result = GetMaxIdx(lf); answer = -1; for (i = 0; i < answerSplit[j].Length; i++) { if (answerSplit[j][i].CompareTo(1) == 0) { answer = i; break; } } if (result == answer) { correct++; } //draw(panel_data_graph_2, j); Console.WriteLine("ans : " + answer + ", res : " + result + "(" + (result == answer ? "O" : "X") + ")"); ListViewItem item = new ListViewItem(j++ + ""); item.SubItems.Add(answer + ""); item.SubItems.Add(result + ""); item.SubItems.Add((answer == result) ? "O" : "X"); listview_test.Items.Add(item); //Thread.Sleep(1000); } chart_test_total.Series[0].Points.AddXY("Correct", correct + ""); chart_test_total.Series[0].Points.AddXY("Wrong", (total - correct) + ""); }
/// <summary> /// Adds and AI to the controller manager /// </summary> /// <returns><c>true</c>, if AI was added, <c>false</c> otherwise.</returns> /// <param name="check">Use GetButtonDown as a parameter for connect code.</param> public bool AddAI(bool check) { if (playerControls.Count < 4) { if (check) { for (int j = playerControls.Count + 1; j < 5; j++) { if (!playerControls.ContainsKey((PlayerID)j)) { AIWrapper aiw = new AIWrapper(-2); playerControls.Add((PlayerID)(j), aiw); Debug.Log((PlayerID)(j) + ": " + aiw + " added"); return(true); } } } } return(false); }
private void button_train_Click(object sender, EventArgs e) { int trainCount = int.Parse(textbox_traincount.Text); string path = textbox_exportpath.Text; AIWrapper wrapper = new AIWrapper(textbox_exepath.Text); wrapper.SetNetwork(textbox_networkpath.Text); wrapper.SetInput(textbox_datapath.Text , int.Parse(textbox_dataoffset.Text) , int.Parse(textbox_datalength.Text) , dataCount); wrapper.SetAnswer(textbox_answerpath.Text , int.Parse(textbox_answeroffset.Text) , int.Parse(textbox_answerlength.Text) , answerCount); wrapper.Train(textbox_exportpath.Text, trainCount); }
/// <summary> /// Adds an AI controller to the game. /// </summary> /// <returns>Whether the AI controller was successfully added.</returns> public bool AddAI(ControllerInputWrapper.Buttons connectCode) { if (playerControls.Count < 4) { foreach (KeyValuePair <PlayerID, ControllerInputWrapper> kvp in ControllerManager.instance.playerControls) { ControllerInputWrapper ciw = kvp.Value; if (ciw != null && ciw.GetButton(connectCode)) { for (int j = 1; j < 5; j++) { if (!playerControls.ContainsKey((PlayerID)j)) { AIWrapper aiw = new AIWrapper(-2); playerControls.Add((PlayerID)(j), aiw); Debug.Log((PlayerID)(j) + ": " + aiw + " added"); return(true); } } } } } return(false); }
// Update is called once per frame void Update() { if (currentPlayerDone) { if (_useAI && _teamUsingAI == CurrentTeam) { bool AIDone = true; foreach (Unit unit in _teamAI) { Steering.SteeringUpdate(unit.transform); if (!Steering.GetSteeringActive(unit.transform)) { if (unit.LeftMoves > 0) { //Debug.Log("Previous: " + _unitCurrentState[unit].StateName); AIDone = false; /* * if (_unitCurrentState[unit].GetExitActionList() != null) * { * //Der er ikke noget i den her liste smarte... * * foreach(IAction action in _unitCurrentState[unit].GetExitActionList()) * { * action.act(unit.gameObject); * } * }*/ State s = AIWrapper.GetDecision(unit.gameObject, ((State)UnitFSM.FSM.CurrentState)); if (s != UnitFSM.FSM.CurrentState && s.StateName != "default") { StateTracker.AddTransition((State)UnitFSM.FSM.CurrentState, s, unit.gameObject); UnitFSM.FSM.CurrentState = s; } List <IAction> acti = ((State)UnitFSM.FSM.CurrentState).GetActionList(); foreach (IAction ac in acti) { ac.act(unit.gameObject); } //TODO Get action //DefendAction att = new DefendAction(); unit.UseTurn(UnitActions.Move, null); //att.act(unit.gameObject); } } else { AIDone = false; } //TODO do AI stuff } if (AIDone) { SwitchPlayer(); } } else if (CurrentTeam == Teams.Team1) { if (Camera.main.transform.rotation.eulerAngles.y < 10 || Camera.main.transform.rotation.eulerAngles.y > 350) { Camera.main.transform.eulerAngles = new Vector3(90, 0, 0); currentPlayerDone = false; } else { Camera.main.transform.Rotate(new Vector3(0, 0, -1) * rotationPerSecond * Time.deltaTime); } } else if (CurrentTeam == Teams.Team2) { if (Camera.main.transform.rotation.eulerAngles.y < 190 && Camera.main.transform.rotation.eulerAngles.y > 170) { Camera.main.transform.eulerAngles = new Vector3(90, 180, 0); currentPlayerDone = false; } else { Camera.main.transform.Rotate(new Vector3(0, 0, 1) * rotationPerSecond * Time.deltaTime); } } } if (OnTeam1 == null && !GameOver) { GameOver = true; if (_teamUsingAI == Teams.Team1) { foreach (Unit u in _teamAI) { StateTracker.WriteHistory(u.parent); } } Debug.Log("Team 2 won"); } else if (OnTeam2 == null && !GameOver) { GameOver = true; if (_teamUsingAI == Teams.Team2) { foreach (Unit u in _teamAI) { StateTracker.WriteHistory(u.parent); } } Debug.Log("Team 1 WON"); } //rotate camera }
/// <summary> /// Adds an AI controller to the game. /// </summary> /// <returns>Whether the AI controller was successfully added.</returns> public bool AddAI(ControllerInputWrapper.Buttons connectCode) { if (playerControls.Count < 4) { foreach(KeyValuePair<PlayerID, ControllerInputWrapper> kvp in ControllerManager.instance.playerControls) { ControllerInputWrapper ciw = kvp.Value; if (ciw != null && ciw.GetButton(connectCode)) { for (int j = 1; j < 5; j++) { if (!playerControls.ContainsKey((PlayerID)j)) { AIWrapper aiw = new AIWrapper(-2); playerControls.Add((PlayerID)(j), aiw); Debug.Log((PlayerID)(j) + ": " + aiw + " added"); return true; } } } } } return false; }
private void button_predict_Click(object sender, EventArgs e) { int paint_size = panel_paint.Width; int i, j, x, y; //for(i = 0;i < paint_size; i++) //{ // for(j = 0;j < paint_size; j++) // { // Console.Write(pixels[i][j] == 1 ? "X" : " "); // } // Console.WriteLine(); //} int paintWidth = panel_paint.Width; int scaleSize = paintWidth / dataWidth + 1; byte[][] arr = new byte[dataWidth][]; byte[] arr2 = new byte[dataWidth * dataWidth]; for (i = 0; i < dataWidth; i++) { arr[i] = new byte[dataWidth]; } for (i = 0; i < paintWidth; i++) { for (j = 0; j < paintWidth; j++) { if (pixels[i][j] == 1) { x = i / scaleSize; y = j / scaleSize; arr[i / scaleSize][j / scaleSize] = 255; arr2[x * dataWidth + y] = 255; } } } //for(i = 0;i < arr.Length; i++) //{ // for(j = 0;j < arr.Length; j++) // { // Console.Write(arr[i][j] == 255 ? "X" : "0"); // } // Console.WriteLine(); //} string path = Directory.GetCurrentDirectory() + @"\temp\predict.txt"; File.WriteAllBytes(path, arr2); AIWrapper wrapper = new AIWrapper(textbox_exepath.Text); wrapper.SetNetwork(textbox_networkpath.Text); wrapper.SetWeight(textbox_biasweightpath.Text); List <List <float> > res = wrapper.Predict(path, 0, dataWidth * dataWidth, 1); int tag = 0; foreach (List <float> lf in res) { foreach (float f in lf) { Console.WriteLine(f); chart_predict.Series[0].Points.AddXY(tag++ + "", (f * 100) + ""); } } File.Delete(path); }