Penalty shootout

Welcome to CG world cup. Your job: Code a penalty shooter and goal keeper!

Rules of the game:

The goal is 700 cm wide and 200 cm tall. If I have to make a rectangle out of it, the goal is ABCD where A is (0,0), B is (0,200), C is (700,200), D is (700,0).

The shooter gives me the coordinate where he will aim. However... there is wind, so your ball final destination may be modified up to 50 positive or negative.

Here's what I'm trying to say...

windX= randint(-50,50)
windY= randint(-50,50)
theFinalCoordinateOfTheBallX= coordinateThatBotGiveX + windX
theFinalCoordinateOfTheBally= coordinateThatBotGivey + windY


The goal keeper gives me the coordinate where he aims. If the distance of the ball final coordinate and the coordinate of the goal keeper is less then 50 cm (using Pythagoras), the ball is saved by the keeper, otherwise it's a goal.

(Note: It is very possible that you did not make a goal, because you MISS the goal. This is possible due to the wind factor. So aiming for (0,0) is not really good idea.)

Each of you has 10 attempts to become goal keeper and shooter.

Communication protocol:

You will receive this from STDIN

R Sx Sy Gx Gy

R-> Round # (Starts from 1 to 10)

Sx -> The x coordinate where the opponent aim when they shoot in previous round (Seperated by comma)

Sy -> The y coordinate where the opponent aim when they shoot in previous round (Seperated by comma)

Gx -> The x coordinate where the oppenent aim when they are goal keeper in the previous round (Seperated by comma)

Gy -> The y coordinate where the opponent aim when they are goal keeper in previous round (Seperated by comma)

Example:

3 57,81 29,90 101,50 27,85

Meaning

This is round 3
In round 1: When your opponent is shooter: He aims for (57,29). In round 2 he aims for (81,90)
In round 1: When your opponent is goal keeper. He aims for (101,27). In round 2 he aims for (50,85)

Another example:

1

This is round 1
No game yet! Prepare your bot for this kind of situation!

Your bot, must give me from STDOUT this:

Sx Sy Gx Gy

Sx -> My x coordinate of where do I aim when I'm the shooter this round.

Sy -> My y coordinate of where do I aim when I'm the shooter this round.

Gx -> My x coordinate of where do I am when I'm the goal keeper this round.

Gy -> My y coordinate of where do I am when I'm the goal keeper this round.

Example:

81 25 71 98

This means you aim for (81,25) when shooting and (71,98) when become goal keeper.

Deciding champion:

Win worths 3 points. Draw worths 1 point. Lost is a null.

After single-round robin, The 4 top high scoring bot will do double-round robin. Among this 4 bots, the champion will be crowned.

Technical details:

The program runs on Windows 7, using Python 2.7.2

Unfortunately, due to my programming skill, I can only receive entry from Python and C. (To Java users, my deepest apology) I'm confident that I can accept entry from C++ and Fortran. I will try when someone gives me a submission in that language...

C programs will be compiled manually using this command:

gcc programFile.c -o programFile

The same thing occurs to Fortran and C++, but since I haven't try, I'm not sure what precisely is the command.

Note: Since using Python 2.7.2, you may want to use raw_input instead of input

Your program may not use/modify/access external source. (Internet, environment variable, making file, accessing folder, external number, etc)

Your program must be deterministic, and please dont over kill random() =p

You may make multiples entry, but please dont help each other..

Make sure you give your bot a name...

FAQ:

Q: Is goals inclusive or exclusive?

A: Inclusive. So if your ball lands at (0,0) and it's out of the goal keeper's reach, it's counts as a goal. (Well irl, it will hit the post)

Q: What is the time limit?

A: 1 second

Q: What happened if my ball ends at (x,-y)

A: No goal Well, irl you cant aim downwards below the ground.

Q: But can my program outputs negative number?

A: Absolutely

Q: Any controllers so I can train my bot?

A: Here

Q: Does my program run 'on and off' or it will keep running until it gets and EOF?

A: On and off On a new round, I will call your bot and pass the necessary info. After you gave my your coordinate, it's done job.

Good luck, you will need it..

• Wait, are bots invoked anew for every round or are the processes kept alive during the game? That is, does my program need to deal with a single round or does it need a loop? Sep 12, 2014 at 10:47
• They're invoked on and off. So just take 1 input, print and done. Another round, on and off. Sep 12, 2014 at 11:14
• AldoSerenaBot.py print -5000 -5000 0 0 Sep 12, 2014 at 11:27
• Isn't this problem a little ill-posed? All somebody else has to do to beat my bot is run it, find out exactly where I'm shooting and blocking, and write a bot to shoot and block in all the right places. Adding a wind factor just changes the likelihood of victory; it doesn't change the optimal solution.
– COTO
Sep 12, 2014 at 12:36
• But your bot has more than one opponent, hopefully. You can't conquer all your enemy in just one bot... Sep 12, 2014 at 12:39

RandomBot, Python

from random import seed,randint
seed(raw_input())
print "%d %d %d %d" % (randint(50,650), randint(50,150), randint(50,650), randint(50,150))


As long as there are no predictable bots to beat, I believe this should be fairly optimal (of course, you could just seed the PRNG yourself to figure out what I'll be doing, but writing a bot to specifically kill one other bot isn't exactly sportsmanship, right? ;)). Obviously, this isn't good at catching, but without anyone to beat, I can't tell how to predict them.

• Isn't this violate the rule of using external source? Randint uses seed, seed is somewhat from external source, right? I may need to reword the rule... Sep 12, 2014 at 10:48
• @Realdeo Usually "external source" refers to files (locally or remotely). If you want to exclude a random seed and the current time as well, you should clarify that. (In which case I'll just seed the PRNG myself.) Sep 12, 2014 at 10:49
• Nice try, but randint use _urandom which uses some external number using seed() or not. I had reword the rule. Thanks for pointing flaw... Sep 12, 2014 at 11:09
• @Realdeo I'd argue that for the purpose of this challenge "external number" means anything that no other bot can reliably reproduce. If I seed the PRNG, and some other user uses the same seed to predict how I will act, they will be successful in that. I don't see why implementing my own PRNG would make my bot any more deterministic or reproducible than that, but I guess I'll have to do that now. (If you're not going by this definition any built-in function might use some "external number" under the hood to compute something.) Sep 12, 2014 at 11:27
• Related Sep 12, 2014 at 11:59

Center, Python

This bot acts just as I would: It stays in the center when being the goal keeper (jumping is hard), and when shooting it does the exact opposite: it aims for one of the corners.

It doesn't care what happened in previous rounds and thus is a good victim for bots that do take this information into consideration.

import random
random.seed(raw_input())
corners = [[50,50],[50,150],[650,50],[650,150]]
corner = random.choice(corners)
print "%d %d %d %d" % (corner[0], corner[1], 350, 100)

• Nondeterministic. Doesn't meet specs. Sep 12, 2014 at 13:52
• @Soham Chowdhury can you expand on that? random itself is deterministic, and I don't see anything in my program that would make it non-deterministic (it produces same output for same input, and always passes through the same states as far as I can tell).
– tim
Sep 12, 2014 at 14:07
• Oh, my bad, then. Sep 12, 2014 at 14:11

Averager (Python)

This is my second serious answer on this site and my first KOTH. Be kind, good sirs.

Yes. The code looks pretty.

rl = lambda l: map(int, l.split(","))
avg = lambda l: sum(l)/len(l)

def take_input():
r = raw_input()
t = True if len(r.split()) == 1 else False
(rno, sx, sy, gx, gy) = (r,'0','0','0','0') if t else r.split()
return (int(rno),) + tuple(map(rl, [sx, sy, gx, gy]))

def g(d):
return((avg(d[1]) + 350)/2, (avg(d[2]) + 100)/2)

def s(d):
return (abs((avg(d[3]) - 350)/2), abs((avg(d[4]) - 100)/2))

def out(d):
print "%d %d %d %d" % (s(d) + g(d))

out(take_input())


Halp and tast k?

• This is not deterministic, I'm afraid. Try make two runs of this program twice with the same input. Result is different. Try again =) Sep 12, 2014 at 13:21
• Oh, damn, I forgot that. Sep 12, 2014 at 13:22
• @Realdeo there you are! Sep 12, 2014 at 13:29

CenteredRandom (Python)

from random import randint, seed, choice

rl = lambda l: map(int, l.split(","))
avg = lambda l: sum(l)/len(l)
avg2 = lambda l, x: avg(l[:-x]) if x < len(l) else avg(l)

corners = choice([[50,50],[50,150],[650,50],[650,150]])

def take_input():
r = raw_input()
seed(r)
t = True if len(r.split()) == 1 else False
(rno, sx, sy, gx, gy) = (r,'0','0','0','0') if t else r.split()
return (int(rno),) + tuple(map(rl, [sx, sy, gx, gy]))

def enemy_is_center(d):
return len(d[3]) > 2 and len(d[4]) > 2 and d[3][-2:] == [350, 350] and d[4][-2:] == [100, 100]

def s(d):
return (100,100) if enemy_is_center(d) else (randint(50, 650), randint(50, 150))

def g(d):
return (corners[0], corners[1]) if enemy_is_center(d) else (randint(50, 650), randint(50, 150))

def out(d):
print "%d %d %d %d" % (s(d) + g(d))

out(take_input())