Skip to content

Instantly share code, notes, and snippets.

@CallumCarmicheal
Created October 9, 2016 17:42
Show Gist options
  • Save CallumCarmicheal/861e48626710908e795410eea11c3d78 to your computer and use it in GitHub Desktop.
Save CallumCarmicheal/861e48626710908e795410eea11c3d78 to your computer and use it in GitHub Desktop.
CodinGame - TheDescent
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
/**
* The while loop represents the game.
* Each iteration represents a turn of the game
* where you are given inputs (the heights of the mountains)
* and where you have to print an output (the index of the mountain to fire on)
* The inputs you are given are automatically updated according to your last actions.
**/
class Player {
struct Mountain {
public int Index;
public int Height;
public static bool operator >(Mountain x, Mountain y) {
return x.Height > y.Height; }
public static bool operator <(Mountain x, Mountain y) {
return x.Height < y.Height; }
};
static void ActionPrint(string Action) { Console.WriteLine(Action); }
static void ActionPrint(int Action) { Console.WriteLine("" + Action); }
static void DebugPrint(string DebugPrint) { Console.Error.WriteLine(DebugPrint); }
static void DebugPrint(int DebugPrint) { Console.Error.WriteLine("" + DebugPrint); }
// Target the mountain
static void TargetMountain(Mountain mountain) {
// Write an action using Console.WriteLine()
// To debug: Console.Error.WriteLine("Debug messages...");
DebugPrint($"Read in Mountain Index=[{mountain.Index}], Height=[{mountain.Height}].");
Console.WriteLine("" + mountain.Index);
}
static void Main(string[] args) {
// game loop
while (true) {
// Define some variables
Mountain mtEverest = default(Mountain);
// Loop through all 9 mountains
for (int x = 0; x < 8; x++) {
Mountain mtnDew = default(Mountain);
// Setup the current mountain
mtnDew.Index = x;
mtnDew.Height = int.Parse(Console.ReadLine());
// Print out our current mountain
DebugPrint($"Read in Mountain Index=[{mtnDew.Index}], Height=[{mtnDew.Height}].");
// Check if the Current Mountain
// is larger than the known largest
// mountain, if so then set the largest
// to the current.
if (mtnDew > mtEverest) {
DebugPrint("Changed Largest mountain.");
mtEverest = mtnDew;
}
}
// Output the current mountain we want to target
TargetMountain(mtEverest);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment