Java Tetris · Technical Details

Home Page
 

Version History 2.11

Changes since 2.1:
  • nightmare mode randomized; now only doubles the score
  • score submission checksum changed
  • some special mode initialization bugs fixed
Changes since 2.0:
  • frequently requested preview feature added (not used by computer player or nightmare mode)
  • scores are reduced to 80% while preview is active and raised to 1000% while in nightmare mode (which will not pay off though)
  • new counter and border layout
  • new menu layout for individual player settings
  • pieces do not just appear but fall into the pit
  • dialog window is now a buggy java.awt.Frame instead of an extremly buggy java.awt.Dialog
  • submit dialog allows several attempts in case of problems
  • new TextBox component for server responses

Changes since 1.02:

  • major class and code rebuild
  • own window (auto-rescaling, menu bar)
  • applet/application hybrid (latter without sounds)
  • many new options including two players mode
  • improved computer player (now receives an average of over 100000 rows)
  • pit frame beautified
  • <B>no</B> HTML tags in highscore entries
 

Highscore Database

The Applet connects to an Oracle System 7 database engine running on a HP workstation. This hard- and software is designed (and used) for heavy-duty jobs so it should do fine for several million Tetris users, too...
 

Cheating

Cheating can be done by several ways. Usign a slow machine is one possibility. Faking a score submission is the most direct approach and is therefore addressed here. There are at least three reasons why you should not cheat:

(a) Cheating is not fair. This is evident for all approaches and needs no further explanation.

(b) Hacking a score is no real challenge. It is possible to send arbitrary scores and it is not very difficult. All you need is a handful of appropriate tools (e.g. a Java disassembler or a debugger). Since the game handling takes place on the client side, it is not possible to have complete control of how the scores were reached. For instance, it would be next to impossible to decide whether a human being or a (slightly randomized and erratic) computer program has been playing. That is the reason why there are no great validation checks.

(c) Last not least, trying to get a high score without playing is work and not fun und will thereby waste your time. There is a kind of checksum appended to your score and you would have to find out how it is encoded. You cannot do this quickly by hand since version 2.11, so you would have to write a bit of code to do it. The whole procedure will take some minutes, maybe some hours. It should not be worthwhile. All you would get are some points. If it is that you are out for, I will gladly email you some.

So please do not spoil the game. Thank you.

 

Computer Player Algorithm

As far as I know it is an open problem whether a "perfect" player (knowing all pieces that will come in advance) could play endlessly or whether there are sequences of pieces that cannot be handled properly.

The computer player algorithm I developped is quite straight-forward and does not provide an answer as it does not play endlessly. The most important part is a function which evaluates a given situation using the depth of the current piece, the structure of it's neighborhood (compactness, gorges) and the number of erasable rows. A weighted sum thereof is calculated for any possible placement of the piece and the best move is performed. The algorithm does not "look into the future" (which would increase the calculation time significantly) and does not slide pieces (which would not be used often).
The selection of the actual weights is critical as it is with most heuristical optimization problems. To improve the algorithm, one could use genetic algorithms to fine-tune the weights and/or a well trained neuronal network.

The nightmare mode uses exactly the same function to figure out which type of piece yields the worst evaluation.

Neither the nightmare mode nor the computer player use the preview. A look-ahead of one piece could increase the computing time by a factor of up to 25! This is far too much, especially on platforms without a just-in-time compiler. In addition, a test showed that the results would not gain much.

 

Source Codes (under construction)

These are the documented sources for the last frozen version of JavaTetris.

TetrisApplet.java
Applet main class, uses Tetris.class, provides audioclips
Tetris.java
Application main class, provides window
Pit.java
All data for a player, provides animation thread
PitView.java
Provides a graphical view for a pit
SubmitDialog.java
Dialog window, includes CGI routines
TextBox.java
Auxiliary component, shows server responses
I am aware that this class design is rather bulky and not very flexible, but I there have been too many performance and synchronization problems in a former loose coupling approach.