NQueens
Project meant for Prolog subject as coursework
Hi! Welcome to my repo. Let me show you a short instruction how to launch the application.
The whole application is written in such stack:
- Backend: Python + Prolog insertions.
- Front-end: React.
Development configurations:
- You need to install all dependencies in three core modules:
- /client:
npm install --save
- /server:
pip3 install -r requirements.txt
- /(root):
npm install --save
- Then return back to the root of the application and launch this command:
npm run development:local
. In such way you will launch simultaneously both of back-end and front-end code.
Production configurations:
- In the root of the application run the command:
npm run prod:local
. This will completele install all required dependencies in all service and start the app in production mode.
What is the code structure?
Back-end structure
- /server/src/pl/*.pl - Prolog files with back-end logic. NQueens combinations and moves are generated here.
- /server/src/api/*.py - Application routes with back-end endpoints.
- /server/src/entities/*.py - Flask/Prolog library connnectivity.
- /server/src/modules/*.py - Modules for applications.
- /server/src/modules/queens/api.py - Main components with all API routes for client-server connectivity.
Front-end structure
- /client/public/*.(png|jpg|mp4) - Public images, videos and other stuff, used in the application.
- /client/src/modules/*.(ts|tsx) - Game components with view based on Domain-Driven Design.
- /client/src/routes/*.tsx - Routes meant for web-game navigation.
How to connect the application with Prolog?
For such purpose I used the PySwip Python library, which helped me to connect the Python back-end with Prolog logic.
Main components:
- prolog = pyswip.Prolog() - Basic class for Prolog-based operations.
- prolog.consult(*.some_path_to_prolog_file) - Helped to read the prolog files with logic and to get the results.
- prolog.query("n_queen(4,Y)") - Query to prolog to get the results of the predicate. Y will contain the results.
In such way I settled powerful Python-Prolog connectivity.
What I haven't done correctly?
The program calculating NQueens with backtracking algorithm. It extracts all possible moves before runtime interpretation of the program. Is such case I cannot use the API in Runtime and inline in the POST/GET requests NQueen calculations for different sizes of desk.
What could be improved?
- Find the way how to calculate the algorithm in Runtime.
- Find the way how to get only current move of the queen, not all possible combinations of queen locations on the desk.
Good luck!