//Method used to generate the base events protected override void generateEvents(){ int i=0; //Generate the original 8 for(i=0;i<8;i++){ StoppingEvent e=null; e = new StoppingEvent((int)((i%4f) + 1), true); events.Add(e); } //Generate the rest of the events for(i=0;i<92;i++){ StoppingEvent e=null; e = new StoppingEvent((int)((i%4f) + 1),i<30? false:true); events.Add(e); } }
//Method used to generate the base events protected override void generateEvents() { int i = 0; //Generate the original 8 for (i = 0; i < 8; i++) { StoppingEvent e = null; e = new StoppingEvent((int)((i % 4f) + 1), true); events.Add(e); } //Generate the rest of the events for (i = 0; i < 92; i++) { StoppingEvent e = null; e = new StoppingEvent((int)((i % 4f) + 1), i < 30? false:true); events.Add(e); } }
private static void OnStopping(RunningModeEventArgs args) { StoppingEvent?.Invoke(null, args); }
//Method used to read in all the trials of the game private List<EventStats> ReadStoppingEvents(XmlNode eventsNode) { List<EventStats> stoppingEvents = new List<EventStats>(); //For all the trials for (int i=0; i<eventsNode.ChildNodes.Count; i++){ int dot=-1; bool go =true; //Make sure were trying to deal with event if(eventsNode.ChildNodes[i].Name =="event"){ foreach(XmlAttribute attri in eventsNode.ChildNodes[i].Attributes){ //Side if(attri.Name.ToLower() == "dot"){ if(int.TryParse(attri.Value.ToLower(),out dot)){ if(dot>4 || dot<1){ NeuroLog.Error("Invalid value for 'dot' at event #" + (i+1).ToString() + ". Needs to be between 1 and 4."); dot = 1; } } else NeuroLog.Error("Invalid value for 'dot' at event #" + (i+1).ToString() + ". Needs to be an int."); } //Color else if(attri.Name.ToLower() == "go"){ if(!bool.TryParse(attri.Value.ToLower(),out go)) NeuroLog.Error("Invalid value for 'go' at event #" + (i+1).ToString() + ". Needs to be an bool."); } //Other attributes that don't have cases else NeuroLog.Error("Unknown attribute '" + attri.Name + "' at event #" + (i+1).ToString() + "."); } StoppingEvent sE = new StoppingEvent(dot,go); stoppingEvents.Add(sE); } } return stoppingEvents; }
//Method used to randomize the order of the list of events protected override void randomizeEvents() { System.Random rand = new System.Random(); int i = 0; //Apply a base randomization to initial ones for (i = 0; i < 8; i++) { StoppingEvent originalStats = (StoppingEvent)events[i]; int spotToMove = rand.Next(i, 8); events[i] = events[spotToMove]; events[spotToMove] = originalStats; } //Apply base randomization to the rest for (i = 8; i < events.Count; i++) { StoppingEvent originalStats = (StoppingEvent)events[i]; int spotToMove = rand.Next(i, events.Count); events[i] = events[spotToMove]; events[spotToMove] = originalStats; } bool ok = true; bool eventGood; i = 0; int cycleCount = 0; //Loop to make sure there are no strings of 4 similiar dot colors do { ok = true; for (i = 8; i < events.Count; i++) { eventGood = true; if (((StoppingEvent)events[i]).Dot == ((StoppingEvent)events[i - 1]).Dot && ((StoppingEvent)events[i]).Dot == ((StoppingEvent)events[i - 2]).Dot && ((StoppingEvent)events[i]).Dot == ((StoppingEvent)events[i - 3]).Dot) { eventGood = false; } if (((StoppingEvent)events[i]).Go == ((StoppingEvent)events[i - 1]).Go && ((StoppingEvent)events[i]).Go == ((StoppingEvent)events[i - 2]).Go && ((StoppingEvent)events[i]).Go == ((StoppingEvent)events[i - 3]).Go) { eventGood = false; } //If there are three in a row, find another element that has a different color and swap the two if (!eventGood) { ok = false; int start = i + 1; if (start >= events.Count) { start = 8; } for (int j = i + 1; j < events.Count; j++) { eventGood = true; if (((StoppingEvent)events[j]).Dot == ((StoppingEvent)events[i]).Dot || ((StoppingEvent)events[j]).Go == ((StoppingEvent)events[i]).Go) { eventGood = false; } if (eventGood) { StoppingEvent originalStats = (StoppingEvent)events[i]; events[i] = events[j]; events[j] = originalStats; break; } else if (j >= events.Count) { j = 8; } } } } cycleCount++; //Attempt 5 loops to fix any bad instances, after 5th proceed anyway if (cycleCount > 5) { ok = true; } }while(!ok); }