Code Monkey home page Code Monkey logo

learntris's Introduction

The Learntris Challenge

Learntris is a set of automated tests that will guide you through implementing your own version of Tetris, that famous Soviet falling blocks game.

The game is a fairly small project suitable for beginners who understand the basic concepts of programming, or for veteran developers looking to pick up a new language.

Along the way, it will expose you to some common software engineering tools, practices, and buzzwords that might not be familiar to you:

Note: This is not a tutorial, in that it will not tell you how to do things, just guide you on what to do -- the implementation is up to you. Are you up for the challenge?

While the tests are about implementing a video game, the real purpose of this exercise is to force you to "fend for yourself" on a project, without relying on tutorial-style guidance.

Instead, the tests present a series of problems that you will need to solve in order to implement the game.

It is entirely up to you how to write the code. Design it however you wish -- there are no wrong answers.

While the tests themselves are written in Python, you are free to implement your game in any language you like. Python will run the tests on your program regardless of what language it is in.

Getting Started

The first step is to git clone or fork this repository and run testris.py. You will need a recent version of Python, preferably Python 3.5 or later. (Remember: Python is only for the test runner. You can use any language you want to write your implementation.)

The output of testris.py will tell you what needs to be done at every step along the way. Just keep running it, and do what it guides you to do. Please read Understanding the Test Results briefly before getting started! The wiki here also has a couple pages on Getting Set Up.

Important: The tests expect you to receive commands as input over standard input (commonly called stdin), e.g. via input() in Python, scanf/getline/getchar/etc in C, and so on. This is not the same thing as command-line arguments that you pass via the terminal: it's what you're using when you type in input to a running program.

If you get stuck, please come join us in our IRC chatroom (links to a Web chat) at #learnprogramming on irc.libera.chat, and we'll try to help you sort it out.

Good luck, and most importantly: have fun!

learntris's People

Contributors

adrian17 avatar amstocker avatar darkf avatar lyurrutia avatar mattpul avatar patrickfalvey avatar raylu avatar sabrial-safi avatar sbakht avatar tangentstorm avatar tmzhuang avatar zachmassia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

learntris's Issues

Program times out.

Running test 24: spawn.J
Spawn location for J
---- sending commands ----
cJPq
---- awaiting results ----
Test 24 failed:

Program times out and does not return 'actual output' and 'expected output'. This is not the only occurrence, it happens for other tests as well.

deal gracefully with IOError when learntris exits prematurely

Example: implementation quits when g is received and testris is still trying to send the matrix data. You'll get:

Running test 3: io.g
g : given
---- sending commands ----
g
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
m m m m m m m m m m
b b b b b b b b b b
c c c c c c c c c c
g g g g g g g g g g
y y y y y y y y y y
o o o o o o o o o o
r r r r r r r r r r
. . . . . . . . . .
. . . . . . . . . .
Traceback (most recent call last):
  File "testris.py", line 158, in <module>
    main()
  File "testris.py", line 155, in main
    if program_args: run_tests(program_args[0], program_args[1])
  File "testris.py", line 131, in run_tests
    run_test(program, opcodes)
  File "testris.py", line 101, in run_test
    program.stdin.write((cmd + "\n").encode('utf-8'))
IOError: [Errno 22] Invalid argument

testris always times out under python3 on windows

On windows, running under git bash:

/c/Python33/python testris.py /c/Python33/python learntris.py just times out, even though /c/Python33/python learntris.py runs correctly.

The given learntris.py implementation is:

import sys
sys.stdin.readline()

(Which should pass the first test.) The --shell option makes no difference.

All variations work fine under python 2.7.6:

/c/Python27/python2 testris.py --shell /c/Python33/python learntris.py
/c/Python27/python2 testris.py --shell /c/Python27/python2 learntris.py
/c/Python27/python2 testris.py  /c/Python33/python.exe learntris.py
/c/Python27/python2 testris.py  /c/Python27/python2.exe learntris.py

Add more comprehensive tests

Right now there is only one test, pertaining to p (print), q (quit), and g (state input). The test suite should cover all working mechanics of Tetris.

unknown error with test 9

Traceback (most recent call last):
File "testris.py", line 165, in main
run_tests(cmdline, use_shell)
File "testris.py", line 135, in run_tests
run_test(program, opcodes)
File "testris.py", line 119, in run_test
program.stdout.read().decode('utf-8').split("\n")]

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe3 in position 18: invalid continuation byte

Oh no! Testris encountered an unexpected problem while
attempting to run your program. Please report the above
traceback in the issue tracker, so that we can help you
with the problem and provide a better error message in
the future.

May be something is wrong with my code .
But it said to report it so here I am.
Here is my code :-https://github.com/ashoknailwal/learntris

suppress output until a test fails

There's no need for the run_tests routine to show anything until a test fails.

Probably we could accomplish this by storing the input/output in some kind of TestResult object, and returning that instead of throwing an exception.

This is more in line with how python's own unittest module works, and opens the door to more interesting front ends in the future.

Can't Execute learntris.py with testris.py in Ubuntu

I have executed the following command in the terminal:-
$python testris.py learntris.py
It giving me error:-
Traceback (most recent call last):
File "testris.py", line 158, in
main()
File "testris.py", line 155, in main
if program_args: run_tests(program_args[0], program_args[1])
File "testris.py", line 127, in run_tests
program = spawn(program_args, use_shell)
File "testris.py", line 77, in spawn
stdout=subprocess.PIPE)
File "/usr/lib/python2.7/subprocess.py", line 679, in init
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

Test 4 unknown issue

Traceback (most recent call last):
  File "testris.py", line 163, in main
    try: run_tests(cmdline, use_shell)
  File "testris.py", line 135, in run_tests
    run_test(program, opcodes)
  File "testris.py", line 111, in run_test
    program.stdin.flush()
OSError: [Errno 22] Invalid argument

Oh no! Testris encountered an unexpected problem while
attempting to run your program. Please report the above
traceback in the issue tracker, so that we can help you
with the problem and provide a better error message in
the future.

Pull test cases directly from extract.py

Currently you need to run extract.py to generate test cases in the tests/ directory.

Now that extract.py generates TestDescription objects, it would make more sense for testris.py to use those objects directly.

Testris should capture exceptions when unable to run learntris.

Basically, if anything happens other than a successful run of the program (where it finishes and returns error code 0), then we should display a helpful message to the user.

As it stands, a failure to launch causes a traceback to be thrown, which isn't useful for anyone who doesn't happen to be learning python. :) Exceptions should be trapped.

Switch away from expect

As said in #3, expect is broken and should be replaced by a custom (or existing) Python module that uses subprocess. It should not be too hard to rewrite the expect-using code to use some API with readline() instead.

FileNotFoundError doesn't exist in python 2

ccca3d6

Traceback (most recent call last):
  File "testris.py", line 184, in <module>
    main()
  File "testris.py", line 155, in main
    except FileNotFoundError as e:
NameError: global name 'FileNotFoundError' is not defined

traceback error after attempting chmod +x executable

Couldn't run './learntris.py' due to a permission error.
Make sure your program is marked as an executable.
localhost:learntris Julie1_macbook_pro$ chmod +x learntris.py
localhost:learntris Julie1_macbook_pro$ ./testris.py ./learntris.py
--------------------------------------------------
Traceback (most recent call last):
  File "./testris.py", line 165, in main
    run_tests(cmdline, use_shell)
  File "./testris.py", line 131, in run_tests
    program = spawn(program_args, use_shell)
  File "./testris.py", line 81, in spawn
    stdout=subprocess.PIPE)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 679, in __init__
    errread, errwrite)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1249, in _execute_child
    raise child_exception
OSError: [Errno 8] Exec format error
--------------------------------------------------
Oh no! Testris encountered an unexpected problem while
attempting to run your program. Please report the above
traceback in the issue tracker, so that we can help you
with the problem and provide a better error message in
the future.

Test 8 stdout error

Traceback (most recent call last):
  File "testris.py", line 163, in main
    try: run_tests(cmdline, use_shell)
  File "testris.py", line 135, in run_tests
    run_test(program, opcodes)
  File "testris.py", line 119, in run_test
    program.stdout.read().decode('utf-8').split("\n")]
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 32: invalid
 start byte

Oh no! Testris encountered an unexpected problem while
attempting to run your program. Please report the above
traceback in the issue tracker, so that we can help you
with the problem and provide a better error message in
the future.

https://github.com/LelouchVlBritannia/learntris - my code is in there ( its a mess)
MinGW/MSYS -- GCC 4.8.1
Python 3.4

Most likely I am doing something really weird but just reporting because it said to report it.

Trouble getting started with Java

I read through the RUNNING PROGRAMS OTHER THAN EXECUTABLE BINARIES section and attempted to apply it to Java, but when I try this i keep getting an error that reads:

File Not Found: C:\windows\system32\java.exe

but it's there. I know because if I run the following in CMD, it works as it should (blank output).
C:\windows\system32\java.exe learntris

allow passing command line options to the subprocess

  • The spawn routine should take a list of strings just like subprocess.Popen.
  • The program_name variable should just be program and it should be a list.
  • The check for whether the program actually exists (in find_learntris needs to be adjusted accordingly. Probably the check for whether the path exists should just be removed, and we should treat a failure to launch the executable like any other exception (i.e., it should stop the test suite and show a test failure...)

Explain diff output format

When a test fails you get a unified diff output like so:

Test 8 failed: output mismatch:
+ . . . .
+ c c c c
+ . . . .
+ . . . .

It would be very helpful to explain what this means, or switch to a less confusing output (maybe "This line is different" instead of - and +.)

collide.floor is weird

#+name: collide.floor
#+begin_src
> cT vvvv vvvv vvvv vvvv vvvv vvvv Pq
. . . . . . . . . . #  0
. . . . . . . . . . #  1
. . . . . . . . . . #  2
. . . . . . . . . . #  3
. . . . . . . . . . #  4
. . . . . . . . . . #  5
. . . . . . . . . . #  6
. . . . . . . . . . #  7
. . . . . . . . . . #  8
. . . . . . . . . . #  9
. . . . . . . . . . # 10
. . . . . . . . . . # 11
. . . . . . . . . . # 12
. . . . . . . . . . # 13
. . . . . . . . . . # 14
. . . . . . . . . . # 15
. . . . . . . . . . # 16
. . . . . . . . . . # 17
. . . . . . . . . . # 18
. . . . . . . . . . # 19
. . . . M . . . . . # 20
. . . M M M . . . . # 21
= Oh, how the Mighty have Fallen...
: Once upon a time, a T tetramino spawned at the
: top of the well, and used the 'v' command to
: move down by one cell 24 times. Sadly, it was
: unable to burrow into the earth and spent the
: remainder of its life standing on its head at
: the bottom of a well.
#+end_src

It moves down past the end of the screen.

In Tetris, as soon as it hits the bottom of the screen it should be considered a hard drop like V and change to a new tetromino.

Learntris assumes the T is still active even as it goes beyond the scren and is dropped... which makes no sense at all. The tetris implementation should select a new tetromino.

It should also not use P because that implies it's still active.

So it should be something like cT vvvv vvvv vvvv vvvv vvvv pq (move 20 rows down, then print normally.)

cc @tangentstorm

Show a nicer message when learntris implementation times out.

Given the following learntris:

#!/usr/bin/env python
while True: pass

...testris produces the following output:

Running test 1: io.q
q : quit
---- sending commands ----
q
---- awaiting results ----
Test 1 failed: <program timed out>

It's probably for the best that the normal explanatory text for the test is missing, since the student should be working on handling 'q' correctly, or removing an accidental infinite loop.

However, there should be some explanation about exactly what timeouts are (i.e. that their implementation took too long to respond and could be locked up.) and probably a reminder about the q command.

(See discussion and notes from @mattpul in #25)

OSError: [WinError 193] %1 is not a valid Win32 application

Running Testris on windows 10, python3.7
Contents of my learntris.py:
import sys
sys.stdin.readline()
the error I'm seeing:

Traceback (most recent call last):
File "testris.py", line 168, in main
run_tests(cmdline, use_shell)
File "testris.py", line 134, in run_tests
program = spawn(program_args, use_shell)
File "testris.py", line 84, in spawn
stdout=subprocess.PIPE)
File "C:\Program Files\Python37\lib\subprocess.py", line 756, in init
restore_signals, start_new_session)
File "C:\Program Files\Python37\lib\subprocess.py", line 1155, in _execute_child
startupinfo)
OSError: [WinError 193] %1 is not a valid Win32 application

Oh no! Testris encountered an unexpected problem while
attempting to run your program. Please report the above
traceback in the issue tracker, so that we can help you
with the problem and provide a better error message in
the future.

https://github.com/LearnProgramming/learntris/issues

step (s) doesn't imply v

In tetris, the clock usually drives the active tetromino down, and after it moves it clears lines.

I think v/V (move down) should clear lines, and s shouldn't really exist anymore

Refuses to work on Windows

For one, winpexpect requires pexpect to be installed, so it will always import the latter first without considering the former. This straight away will lead to it not working.

Even with winpexpect, it hangs, presumably while waiting for input or something. I propose the expect-related stuff be switched out for a subprocess-based matcher (See also: #4)

deal gracefully with OSError from learntris

Example: maximally obtuse TDD programmer does exactly what the error messages indicate, and no more:

$ ./testris.py 

Testris is the test runner for Learntris. Learntris is
the part *you* write, in whatever language you prefer.

If you're seeing this message when you tried to run
testris.py, it means testris can't find your code!

Your first step is to write a *console-mode* program
(one that does absolutely nothing!) and tell testris
where to find it:

    ./testris.py [/path/to/learntris] [arguments]

The path should refer to a physical file on disk, so if
you need command line arguments, create a wrapper program.
The default path is "./learntris".

You can pass extra arguments that will be passed to the
guest learntris program.

If you need more help with setting up, try reading:
https://github.com/LearnProgramming/learntris/wiki/Getting-Set-Up

Once testris is able to launch your program, this message
will be replaced with instructions for implementing your
first feature.

File not found: ./learntris
$ touch learntris
$ ./testris.py 

[Errno 13] Permission denied
Couldn't run './learntris' due to a permission error.
Make sure your program is marked as an executable.
$ chmod a+x learntris 
$ ./testris.py 
--------------------------------------------------
Traceback (most recent call last):
  File "./testris.py", line 168, in main
    run_tests(cmdline, use_shell)
  File "./testris.py", line 134, in run_tests
    program = spawn(program_args, use_shell)
  File "./testris.py", line 84, in spawn
    stdout=subprocess.PIPE)
  File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
    raise child_exception
OSError: [Errno 8] Exec format error
--------------------------------------------------
Oh no! Testris encountered an unexpected problem while
attempting to run your program. Please report the above
traceback in the issue tracker, so that we can help you
with the problem and provide a better error message in
the future.

  https://github.com/LearnProgramming/learntris/issues

There are probably tons of possibilities for OSError, and maybe not all of them can be gracefully handled without risking being misleading. Anyway, food for thought.

remove test numbers and improve diff explanation.

Given the following learntris...

#!/usr/bin/env python
print('x')

We get:

Running test 1: io.q
q : quit
---- sending commands ----
q
---- awaiting results ----
: The 'q' command instructs learntris to quit.
:
: Learntris should not produce any output unless
: explicitly instructed to do so.
---- expected results ----

Test 1 failed: output mismatch:
- x

There are several cleanups that should be made:

  1. The lines Running test 1: io.q and Test 1 failed: output mismatch: should be modified so that both refer to the test name and neither refers to the number.
  2. There should be an explanation of the diff output.

Here is an example of how an improved version might look:

Running test: [io.q]
q : quit
+--- sending commands ----
q
+--- awaiting results ----
: The 'q' command instructs learntris to quit.
:
: Learntris should not produce any output unless
: explicitly instructed to do so.
+--- expected results ----
+--- output mismatch! ----
:
: Test [io.q] failed.
:
: The following diff show the changes required
: to pass the test.
:
:  '-' indicates a line to be removed,
:  '+' indicates a line to be added.
+-------------------------
- x

Need documentation

As it stands, there is nothing showing how to get started with learntris or even really what it does. Ideally there would be a tutorial or just a description of all of the tests that programs should pass.

Issue with trying to run "python testris.py learntris.py"

When I use C:\Users\aaron\learntris>python testris.py
I get the typical message of: "Testris is the test runner for testris... File not found: ./learntris"

Now, this is the message I get whenever I try to run: C:\Users\aaron\learntris> python testris.py learntris.py
I think that this should work (I'm using windows cmd.exe and python is in my path).

Any assistance would be wonderful!


Traceback (most recent call last):
File "testris.py", line 165, in main
run_tests(cmdline, use_shell)
File "testris.py", line 131, in run_tests
program = spawn(program_args, use_shell)
File "testris.py", line 81, in spawn
stdout=subprocess.PIPE)
File "C:\Program Files (x86)\Python35-32\lib\subprocess.py", line 947, in init
restore_signals, start_new_session)
File "C:\Program Files (x86)\Python35-32\lib\subprocess.py", line 1224, in _execute_child
startupinfo)
OSError: [WinError 193] %1 is not a valid Win32 application


Oh no! Testris encountered an unexpected problem while
attempting to run your program. Please report the above
traceback in the issue tracker, so that we can help you
with the problem and provide a better error message in
the future.

https://github.com/LearnProgramming/learntris/issues

testris.py does not pass with my python installlation on Windows 8.

The error:

Traceback (most recent call last):
File "testris.py", line 154, in
main()
File "testris.py", line 151, in main
if program_args: run_tests(program_args[0], program_args[1])
File "testris.py", line 121, in run_tests
program = spawn(program_args, use_shell)
File "testris.py", line 77, in spawn
stdout=subprocess.PIPE)
File "C:\Python27\lib\subprocess.py", line 711, in init
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 948, in executechild
startupinfo)
WindowsError: [Error 193] %1 is not a valid Win32 application

Problem with 'extract' module in testris

Dear community,

I'm new to this so please forgive me if I can't see the wood for the trees. When I compile and run the 'testris.py' file I get the following error relating to a module. The output is pasted below.

Traceback (most recent call last):
  File "F:\Programming\Python\learntris\PythonApplication1\PythonApplication1\PythonApplication1.py", line 159, in main
    run_tests(cmdline, use_shell)
  File "F:\Programming\Python\learntris\PythonApplication1\PythonApplication1\PythonApplication1.py", line 124, in run_tests
    for i, test in enumerate(extract.tests()):
NameError: name 'extract' is not defined

Would someone be so kind as to give me a hint at where I'm going wrong?

I'm using Visual studio 2015 RC to build the testris code and I'll probably continue using python to build my version of 'learntris'

Many thanks

Add graphcial learntris frontend

Being able to graphically play your game would be a great motivation.

This would be best done in either standard Python (i.e. with Tkinter), or as a Web app (preferably using the Python standard library again, or at least bottle.py so that we could drop it in.)

A Web app could use WebSockets to communicate, and Canvas or SVG to draw.

If anyone wants to attempt this (feel free!), don't hesitate to drop by #learnprogramming (see the README for a link) and mention it. We wouldn't mind to guiding you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.