Skip to content

Instantly share code, notes, and snippets.

@David-Mimnagh
Created December 14, 2016 11:26
Show Gist options
  • Save David-Mimnagh/5b7a294098b656482fc2fb78aa9ca7aa to your computer and use it in GitHub Desktop.
Save David-Mimnagh/5b7a294098b656482fc2fb78aa9ca7aa to your computer and use it in GitHub Desktop.
public class Bot
{
public int Low { get; set; }
public int High { get; set; }
public int DestLow {get;set;}
public int DestHigh {get;set;}
public int OutDestLow {get;set;}
public int OutDestHigh {get;set;}
public Bot(int low, int high)
{
Low = low; High = high;
}
}
static void AssignBotDestValues(string command, List<Bot> botList)
{
int start = "bot ".Length;
int to = command.IndexOf(" ", start);
int botGivingID = Int32.Parse(command.Substring(start, to - start));
string firstWord = null;
start = command.IndexOf("low to ") + "low to ".Length;
to = command.LastIndexOf(" and high");
string lowValTo = command.Substring(start, to - start);
firstWord = lowValTo.Substring(0, lowValTo.IndexOf(" "));
switch (firstWord)
{
case "bot":
{
lowValTo = lowValTo.Replace(firstWord, String.Empty);
int botGettingID = Int32.Parse(lowValTo);
botList[botGivingID].DestLow = botGettingID;
}
break;
case "output":
{
lowValTo = lowValTo.Replace(firstWord, String.Empty);
int outputID = Int32.Parse(lowValTo);
botList[botGivingID].OutDestLow = outputID;
}
break;
default: { } break;
}
start = command.LastIndexOf("high to ") + "high to ".Length;
string highValTo = command.Substring(start);
firstWord = highValTo.Substring(0, highValTo.IndexOf(" "));
switch (firstWord)
{
case "bot":
{
highValTo = highValTo.Replace(firstWord, String.Empty);
int botGettingID = Int32.Parse(highValTo);
botList[botGivingID].DestHigh = botGettingID;
}
break;
case "output":
{
highValTo = highValTo.Replace(firstWord, String.Empty);
int outputID = Int32.Parse(highValTo);
botList[botGivingID].OutDestHigh = outputID;
}
break;
default: { } break;
}
}
static void MoveValues(Bot currBot, int currLow, int currHigh,int destLow, int destHigh, List<Bot>botList)
{
botList[destLow].Low = currLow;
botList[destHigh].High = currHigh;
currBot.Low = 0;
currBot.High =0;
}
static void TraverseCommands(List<string> commandList, List<Bot> botList, int[] outputs)
{
for (int i = 0; i < commandList.Count; i++)
{
if(i>0)
if (commandList[i-1].Contains("value"))
{
GiveValueToBot(commandList[i-1], botList);
commandList.Remove(commandList[i-1]);
}
if(commandList[i].Contains("value"))
{
GiveValueToBot(commandList[i], botList);
commandList.Remove(commandList[i]);
}
}
for (int i = 0; i < commandList.Count; i++)
{
AssignBotDestValues(commandList[i], botList);
}
int index =0;
foreach(Bot b in botList)//Check to see if any bot has all 4 values it needs to pass it's chips on
{
index++;
if(b.High != 0 && b.Low != 0)
{
if (b.Low == 17 && b.High == 61)
Console.Write("FOUND THE MUDDAFUCKA");
if(b.DestHigh !=0 && b.DestLow !=0)
{
MoveValues(b,b.Low,b.High,b.DestLow, b.DestHigh, botList);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment