Four-Man Standoff


Guns are overrated. A true Scotsman's standoff goes like this:

  • Prepare
  • Throw at enemy with most health
  • Repeat (if by some miracle you're still alive)

While this seems trivial, it's probably not a terrible strategy. Since guns and grenades both have a two-turn cycle, this is by far the more efficient1 way to deal damage.

Of course, if all three opponents shoot me on the first round it's no good. But not much else would be, either.

public class Grenadier {
    public static void main(String[] args) {
        if(args.length < 2)
        String[] list = args[1].split(" ");
        if(list.length < 4)
        if(list[0].charAt(list[0].length()-1) != 'P'){
        int target = 1;
        for(int i=2;i<4;i++)
                target = i;


Compile/run in the standard Java way:

> javac
> java Grenadier arg0 arg1

1 Pointless footnote

Asimov's Rule Number 0 Bot - Python

A robot may not harm humanity, or, by inaction, allow humanity to come to harm.

Pretty straight forward, he'll attack the first player he sees holding a grenade in order to protect the majority of humans. If no one is a threat to the majority of humans, he'll do nothing.

import sys

def total_humans_alive(humans):
  return sum([is_alive(human) for human in humans])

def is_alive(x):
  return int(x.split(",")[0]) > 0  

def is_threat_to_humanity(lastAction):
  return lastAction == "P"

action = "N"
threat_id = 1
humans = sys.argv[2].split()[1:];

if total_humans_alive(humans) == 3:
  for human in humans:
    if is_threat_to_humanity(human[-1]):
      action = "S" + str(threat_id)
    threat_id= threat_id+ 1

print action

Run it like:


Han Solo - Python

Han shot first. In this case, he'll shoot first by picking the closest target alive.

import sys

def is_alive(player):
  return int(player.split(",")[0]) > 0

closest_living_target = 1;

for player in sys.argv[2].split()[1:]:
  if is_alive(player):
    action = "S" + str(closest_living_target)

  closest_living_target = closest_living_target + 1

print action

Run it like:


Note: This is the first thing I ever wrote in Python, so if you see any python-specific bad practices, please let me know.