The Let's Play Archive

EXAPUNKS

by Carbon dioxide

Part 29: Xtreme League Baseball

Part 29 - Xtreme League Baseball

=== Trash World Inbox ===

Last time, I ended with another nonogram puzzle.

Several people solved it, here's Regallion's submission.



It's a computer, of course.


=== Xtreme League Baseball ===

Last time, I beat deadlock in a hacker battle.

Curious how enthusiastic everyone gets about the battles.
Something about competition really energizes the spectators.
It makes me wonder...




Two votes for "What the point is?"

What the point is?

Perhaps there is no immediate point.
I am able to tolerate ambiguity.
Even though I may not always like it.




A bit scared of me, are they?



Looks like the next assignment has to do with a Baseball database.

You should be glad I've been reading up on sports.
Remember when I said I'd figure out the money situation?
I've designed a new rating system for extreme baseball players.
It's based on a multivector analysis of all the stats I could find.
In other words, I have a way to predict winning teams that's pretty much infallible.
A few bets here and there and I'll be rich.


Um, I don't think you can predict sport match outcomes to such a degree. But okay, if you say so.


OST: Code and Registers

The assignment:
- The hosts active and penalty contain files that correspond to extreme baseball players (files 200-299), along with a directory file that contains a list of those files' IDs (file 199). Each player file contains their name and the following statistics in this order: BA, ZA, APB, WRT, OI, OD, PC and PS.
- Create a file in your host with the name of the player with the highest score using EMBER-2's algorithm:
SCORE = (BA + ZA + APB) / 3 + (WRT * OI) / OD + (PC - PS) * 20
- Players in the penalty host should be ignored, as they are currently banned from the game.


Okay, so all the action is in the active host. I'm not really familiar with the details of Xtreme Baseball, so I don't know what those stats mean but this assignment looks an awful lot like math. I'm sure I can figure it out though.

Before that, let's have a bit of fun.



Having an EXA go round the diamond gets us the Steam achievement HOME_RUN, description "Participate in America's new pastime."

Let's start by just writing the algorithm. Ember's formula has the stats in the order they appear in the files, which makes it simple because I don't need to SEEK back.

code:
LINK 800
GRAB 199

MARK NEXT
COPY F X
REPL CALCULATOR
JUMP NEXT

MARK CALCULATOR
GRAB X

SEEK 1
ADDI F F X
ADDI X F X
DIVI X 3 X

MULI F F T
DIVI T F T

ADDI X T X

SUBI F F T
MULI T 20 T
ADDI X T M
SEEK -9999
COPY F M
This EXA grabs the file with the IDs, and makes a calculator REPL for each file ID. Those grab the files, skip the player's name for now, and execute the algorithm. It's good to remember that it's legal to use ADDI F F X to add two consecutive values in the file together. Other than that, it's just a straight implementation of the formula, using X for the part before the first plus sign, T as a buffer for the part in the middle, and then, after adding those together in X, T again for the third part. Then the EXA sends the resulting score to M, and follows with the name of the player.

Another EXA will have to figure out which player has the highest value. An initial attempt:
code:
;XB
MAKE
COPY 0 F

MARK NEXT
SEEK -9999
COPY M X
TEST X > F
FJMP SKIP

COPY M F
SEEK -9999
COPY X F
JUMP NEXT
MARK SKIP
VOID M
JUMP NEXT
XB stays in the home host, makes a file and puts in 0 as an initial score. Then it waits for the first score on M, tests if it's larger (which is always true for the first value, but may be false later). If it's not larger, it VOIDs the name coming in over M, otherwise it writes it to F, and then writes the new score to the first position of F. That way, F will have score, name in that order.

There's still some stuff missing, for instance how do you clean up at the end? Since the code so far only has an activity of one (the one LINK to the active host), I decided to first solve these last bits with low activity in mind.

That was harder than it seems, though. XA creates replicas so fast that the M messages start interfering with each other. There are solutions such as having them wait for each other, but to do that in a fast way, you'd need to prevent the last one from getting stuck which might require a KILL or something. Since that's not allowed for low activity, I went for a slower solution instead.
code:
;XA LOCAL

LINK 800
GRAB 199

MARK NEXT
COPY F X
REPL CALCULATOR
COPY 0 M
TEST EOF
FJMP NEXT

MODE
NOOP
NOOP
NOOP
NOOP
COPY 0 M

MARK CALCULATOR
GRAB X

SEEK 1
ADDI F F X
ADDI X F X
DIVI X 3 X

MULI F F T
DIVI T F T

ADDI X T X

SUBI F F T
MULI T 20 T
VOID M
MODE
ADDI X T M
SEEK -9999
COPY F M
XA starts in LOCAL mode now. After every REPL, the main one sends a 0 to local M. the calculator waits for that before switching to GLOBAL mode and sending its data to XB. Also, I added a TEST EOF to the main EXA. If the EOF is reached it doesn't just die, instead it waits some cycles so the final calculator can finish, then it sends a 0 in GLOBAL mode.
code:
;XB
MAKE
COPY 0 F

MARK NEXT
SEEK -9999
COPY M X
TEST X > F
FJMP SKIP

COPY M F
SEEK -9999
COPY X F
JUMP NEXT
MARK SKIP
TEST X = 0
TJMP END
VOID M
JUMP NEXT

MARK END
SEEK -9999
VOID F
XB has to test for this zero now. It does that in the SKIP branch, since 0 is always lower than the high score, and the SKIP branch is quite fast anyway. If it receives the zero, after jumping to END it deletes the score from the file, leaving only the player name, which is the requirement.



This solution runs at 168/49/1. Top percentiles are 79, 39 and 1 respectively.

Time for other optimizations.



This code speeds things up significantly, with 101/52/3. The main change is that I have a separate TIMER EXA which allows the algorithms to run in parallel, only synchronizing for the parts where they need M traffic. The TIMER EXA also checks when there's no EXAs left to send, in which case it goes home to kill XB and clean up the file faster than XB could do itself.

By the way, that FJMP followed by a JUMP at the bottom looks a big ugly but if I don't do it I need an extra NOOP for some reason, which makes the solution a single cycle slower.

At this point I thought of something silly that worked for other assignments: what if I don't calculate anything and just put a file for each name in the home host (9 squares, there's never more than 10 active players, so with some luck we could make that work). No dice, the devs thought of that one, and having multiple files in the home host fails the tests.

I spent a while looking for further speed improvements. I have several ideas. If it would be possible to simplify the algorithm itself that would save time. Another way would be to parallellize the greatest score check somehow, for instance by comparing them pairwise. But with the limited functionality of the single M register I couldn't get anything to work. Optimizing these assignments is really getting quite hard at this stage of the game.


I'll try to get a lower size now.
code:
;XA

LINK 800
COPY 199 X

MARK GRABLOOP
ADDI X 1 X
REPL GRAB
NOOP
TEST X > 300
FJMP GRABLOOP

LINK -1
KILL
GRAB 400
VOID F

MARK GRAB
GRAB X

SEEK 1
ADDI F F X
ADDI X F X
DIVI X 3 X
MULI F F T
DIVI T F T
ADDI X T X

SUBI F F T
MULI T 20 T
ADDI X T M
SEEK -9999
COPY F M

:XB

MAKE
COPY 0 F

MARK NEXT
SEEK -9999
COPY M X
TEST X > F
FJMP SKIP

COPY M F
SEEK -9999
COPY X F
JUMP NEXT

MARK SKIP
VOID M
JUMP NEXT
Both EXAs in GLOBAL mode now. 519/40/3. One above the top percentile.

The main trick is to get rid of the code that reads the file IDs from file 199. The alternative (looping through all valid file IDs) isn't really any less lines of codes, but because this is so much slower, only a single NOOP in the GRABLOOP is enough to prevent M communication in the wrong order. Having XA KILL XB is also slightly less code than having XB handle this.

I tried removing the initial COPY 199 X and funnily enough that works in most test cases - running the algorithm on the index file just happens to return a negative score most of the time, which is ignored by XB. Sadly, there's at least one test case where it generates a high positive score and writes an invalid result, so we do need this line.

That's it for optimization this update.

Okay, uh. Hmm.
Processing.
It turns out sports betting is not, in fact, a good way to make money.
You should have said something.




The first vote.

Did you know people pay real money for items in online games?



And the vote for the intro for next week's assignment.