Przejdź do głównej zawartości

Unit testing functions containing user input and side effects - Pytest

Testing is good for you and your code,  but sometimes can be tricky!   Attribution Flaticon A while ago, as a newbie programmer, who just finished his first course, the only thing I knew than about testing, was a big mention made by Cisco Networking Academy or Python Institute itself, claiming that unit testing is a must, is broad and complex topic, and that it will be covered in separate course... There even is a site on Python Institute dedicated to this topic, but as for present day (01.11.2023) no course is available there... but there is a chance, because they give us a time window when this course should be available ( https://pythoninstitute.org/python-for-testing-essentials )!  So while undertaking a couple of courses I stumbled upon Pytest library, and scratched UnitTest. The former was more broadly described during CS50P course brought by Harvard University, the latter was somewhat described in one of courses I've undertaken on Udemy so far. For now let's stick ...

Choosing the CS50P final project's scope...




Easy peasy right?

Yeaaaaa....

After few hours of thinking, I made a decision to create an arcade space shooter in a bit modern way.

My project was going to be a shooter similar to classic Asteroids, but instead of shooting to space rocks, I wanted them to be ships, which can shoot back at the player. Also I wanted to make an in game menu, witch player profile creation, gathering statistics and storing them into a database. those stats should be accessible from in game menu and shown in game window.

Easy! What can go wrong...❗

 

It turns out that almost everything 😁

The first problem was that i did know nothing about game dev, databases and game states... And i know not much right now either! But let's not spoil the whole story!

 

1. Learn the tool.

The decision was to use Pygame library. So after few days of watching YouTube videos, and reading the docs work has begun... Or I thought it was.

I was able to create game window, some surfaces, and add sprites to the game. I also added enemies, and made them appear in random places! WOW!

And that's it! 

I hand no idea, how to make the player character move!...


2. Math...

So I wondered how to do things... and vectors got in the way. After a week or so I was able to rotate and move my char on the surface, but there still was a problem, mainly I did not know how to rotate it. Damn vectors! So another research begun. Rotation, angle to, speed aaaaaa! With rotation there goes hit boxes, there goes sprite rotation... there goes shooting point rotation and calculating where all those point should be in space and time... I mean what the hell?! Why game dev is so heavily math dependant? How little I knew. 

Next thing was animations, and all things mentioned above was relevant for that too. Not even mention more sophisticated enemy movement, and the most important thing in this type of games, SHOOTING.

The further i went the more lost I felt, more depressed and felt huge pressure to finish the project. but I didn't knew how to do it.

It turned out way over my head, skills and knowledge. Trying to create a projectile and move it killed me.

The final step I got too is what you can see at the movie below:




3. The idea downgrade...

So let's stick to the game idea, but change the space and movement aspect. Let's make a more Space Invaders type game. No problem!

The first what i wanted to do was game menu, and game states. So I tried and tried and tried some more... Got even more frustrated and couldn't understand how to make it work... 💥

So it appears gamedev and its concepts are not yet reachable for me. So the only thing which remained was to...


4. Change the project 💡

I wanted to gather data, and make some statistics, with databases usage. So I transferred it into a Sudoku Solver. Solving included data, such as time, success rates, methods, rows read, rows written, dates etc. And so I thought, maybe after some little codding success I will be able to overcome that program states, and make some simple menu based on text and terminal. So this is it. Sudoku Solver with statistic was going to be born!

 

from dlxsudoku import Sudoku
import numpy as np
import argparse
import datetime
import tabulate
import sqlite3
import random
import typing
import time
import tqdm
import csv
import sys
import os
import re

 

Stay tuned!


Komentarze

Popular posts

Unit testing functions containing user input and side effects - Pytest

Testing is good for you and your code,  but sometimes can be tricky!   Attribution Flaticon A while ago, as a newbie programmer, who just finished his first course, the only thing I knew than about testing, was a big mention made by Cisco Networking Academy or Python Institute itself, claiming that unit testing is a must, is broad and complex topic, and that it will be covered in separate course... There even is a site on Python Institute dedicated to this topic, but as for present day (01.11.2023) no course is available there... but there is a chance, because they give us a time window when this course should be available ( https://pythoninstitute.org/python-for-testing-essentials )!  So while undertaking a couple of courses I stumbled upon Pytest library, and scratched UnitTest. The former was more broadly described during CS50P course brought by Harvard University, the latter was somewhat described in one of courses I've undertaken on Udemy so far. For now let's stick ...

The first step...

Hello world!  This would be appropriate start of this project. Because it is the most canonical and very first output of your code, when you start learning code and write your first program. I'm a bit further in this process and currently working towards finalization of the CS50P final project. While figuring out what should I do to finish the course, one of my thoughts was to start documenting my way to achieve this. Write about my plan, problems I encounter, and solutions I come up with. So this is the introduction of what You'll find on this blog. print ( "Hello, world!" ) In the next post will consist off my plan in few points. Happy codding!