项目作者: dstepanets

项目描述 :
[School 42] A variant of Tetris game
高级语言: C
项目地址: git://github.com/dstepanets/fillit.git
创建时间: 2019-05-03T15:34:19Z
项目社区:https://github.com/dstepanets/fillit

开源协议:

下载


Fillit

A variant of the Tetris game. Fit a set of Tetrimino pieces into the smallest possible square.

Description

The program takes a set of Tetriminos. And fits them into the smallest possible square, without rotation.

A tetrimino is defined like this, on a 4x4 square:

  1. ....
  2. ..##
  3. .##.
  4. ....

An input file can contain up to 26 such pieces, separated by empty lines. On a solution map pieces are marked by letters in alphabetical order:

  1. ABBBB.
  2. ACCCEE
  3. AFFCEE
  4. A.FFGG
  5. HHHDDG
  6. .HDD.G

This is the project of the Algorithms branch of the School 42 curriculum.

Detailed description of the task: fillit.en.pdf

Usage

Compile with make. Run like this:

  1. ./fillit <tetriminos_file>

You can use test_files or create your own.

Algorithm

Simple backtracking was enough for this exercise. First, we count tetriminos and create the smallest map on which this number of 4-square pieces could theoretically fit. Then place them one by one, trying all combinations, and returning to the previous piece if the current one doesn’t fit anywhere.

Once we tried all the pieces in all positions and haven’t found the solution, we extend our map by one and start all over.