Difference between revisions of "User:Nightmareci"

From TetrisWiki
Jump to navigation Jump to search
(make it work for any kind of row)
Line 79: Line 79:
 
</pre>
 
</pre>
 
==== Perl Version ====
 
==== Perl Version ====
DeHackEd made this one, and I'm not sure what conditions he has over it; just assume it's freeware for now:
+
DeHackEd made this one, and I'm not sure what conditions he has over it. I made some fixes to it, so it works on any type of row, not just pfrow:
 
<pre>#!/usr/bin/perl
 
<pre>#!/usr/bin/perl
  
Line 89: Line 89:
 
print "$1&lt;playfield&gt;$2\n";
 
print "$1&lt;playfield&gt;$2\n";
 
}
 
}
elsif (/^\{\{pfrow ?\|(.*)\}\}$/) {
+
elsif (/^\{\{(?:pf|tnet|width[3-6])row *\|(.*)\}\}$/) {
#$begin = $1;
 
 
$code = $1;
 
$code = $1;
#$end = $3;
 
 
 
@stuff = split(/\|/, $code);
+
@stuff = split(/\|/, $code);
#print STDERR "$code @stuff\n";
 
 
print join("", @stuff). "\n";
 
print join("", @stuff). "\n";
 
}
 
}

Revision as of 00:38, 25 July 2009

Definitions

Terms in TGM legend and Glossary will be used in my pages, with the original definitions. If you encounter a confusing term, look in TGM legend first, then Glossary if it's not in TGM legend.

Row Numbering

In my pages, row numbering follows this convention:

  1. Vanish zone
  2. First visible row
  3. Second visible row
  4. ...
  5. Nineteenth visible row
  6. Twentieth visible row (last)

Row number 0 is the topmost row and successive rows are beneath it. In the listing above (which is TGM1's row configuration), there is a total of 21 usable rows.

My Own Pages

Detailed description of Tetris The Grand Master

SRS

Other Stuff

Playfield Template Converters

The old playfield templates are problematic for both bandwidth and server load; the new <playfield> parser extension alleviates those problems, and these can convert pages to the new syntax:

Awk Version

I, Nightmareci, made this one; I put it in the public domain, so do as you wish with it.

#!/bin/awk -f

/\{\{ *pfstart *\}\}/,/\{\{ *pfend *\}\}/ {
	sub(/\{\{ *pfstart *\}\}/, "<playfield>")
	sub(/\{\{ *(pf|width[3-6]|tnet)row */, "") && gsub(/\||\}\}/, "") && gsub(/ /, ".")
	sub(/\{\{ *pfend *\}\}/, "</playfield>")
	print
	next
}

1

Python Version

I, Nightmareci, made this one; I put it in the public domain, so do as you wish with it.

#!/usr/bin/env python
import fileinput
import re

start = re.compile(r'\{\{pfstart\}\}')
row = re.compile(r'\{\{(?:pf|tnet|width[3-6])row *([^}]*)\}\}')
end = re.compile(r'\{\{pfend\}\}')
# Because we need more explicit control over moving between lines, we must use
# an actual FileInput instance.
files = fileinput.input()

for line in files:
	# Find the beginning of the playfield.
	if start.search(line):
		# Replace '{{pfstart}}' with '<playfield>'
		print start.sub('<playfield>', line, 1),

		for line in files:
			# If the current line is '{{pfend}}', replace with
			# '</playfield>' and break out
			if end.search(line):
				print end.sub('</playfield>', line, 1),
				break
			# If this is not '{{pfend}}', this line is a row, so
			# convert it to the new syntax.
			else:
				# First, the template arguments are extracted
				# from the row, then the pipes, '|', are
				# removed, then spaces, ' ', are changed to
				# periods, '.'.
				print row.sub(r'\1', line, 1).replace('|',
						'').replace(' ', '.').upper(),
	# This line isn't the beginning of a playfield, so just print.
	else:
		print line,

Perl Version

DeHackEd made this one, and I'm not sure what conditions he has over it. I made some fixes to it, so it works on any type of row, not just pfrow:

#!/usr/bin/perl


while (<>) {
	chomp;
	
	if (/^(.*)\{\{pfstart\}\}(.*)$/) {
		print "$1<playfield>$2\n";
	}
	elsif (/^\{\{(?:pf|tnet|width[3-6])row *\|(.*)\}\}$/) {
		$code = $1;
		
		@stuff = split(/\|/, $code);
		print join("", @stuff). "\n";
	}
	elsif (/\{\{pfend\}\}(.*)$/) {
		print "</playfield>$1\n";
	}
	else {
		print "$_\n";
	}

}
ZZZ
Z  Z
ZZZ
Z  Z