Skip to main content
9 votes
Accepted

Solve 8-tile sliding puzzle

Here's the code you want to speed up: ...
Quuxplusone's user avatar
  • 19.4k
6 votes
Accepted

Game of Fifteen - A Sliding Puzzle Game

The GOOD, there are no MAGIC numbers, good job! The naming conventions of the constants and enums follow the current coding standards. The code is quite readable which suggests it is maintainable. ...
pacmaninbw's user avatar
  • 24k
6 votes

Npuzzle solver using A* with Manhattan + Linear Conflict (Updated Code)

Don't put implementation in header files You moved all of your code into header files. That's not what they are for. It is better to have only the declarations of the classes and functions in the .h ...
G. Sliepen's user avatar
  • 58.3k
6 votes
Accepted

Simple N Puzzle console game

I think you're real close to the ask of the problem. I have two main bits for you to change up: Your Tile class has no way of setting the tile value. Change so ...
Jesse C. Slicer's user avatar
5 votes

A* search on 4x4 sliding tile puzzle scales poorly

You're doing the same mistake that everyone who posts that their A* is slow is doing. You're using the wrong data structure for your open and closed structure. The closed should be a set, usually ...
Emily L.'s user avatar
  • 16.6k
5 votes
Accepted

Optimizing the code for 8-puzzle in Python

Initial thoughts: Why optimize your code when there are 362 880 possibilities, the best way to optimize is to reduce the number of possibilities. The complexity here is O(n²!) meaning that it quickly ...
Benoît P's user avatar
  • 799
4 votes
Accepted

A function that moves a tile in the game of fifteen

As suggested in this answer, storing the board as a one-dimensional array would make the logic much simpler. For one thing, the location of the space could be represented as a single ...
200_success's user avatar
4 votes

A function that moves a tile in the game of fifteen

Reading past array bounds Each of your four checks has the possibility of reading past array bounds. Very bad things can happen when that happens. I will illustrate with an example: Let ...
JS1's user avatar
  • 28.5k
4 votes
Accepted

Game of 15 - A* search

I'll focus on the readability part of your code: Don't import modules you're not using. (import itertools) Don't import modules in the middle of your code. All the ...
Grajdeanu Alex's user avatar
4 votes
Accepted

Storing configurations of states to a database - Breadth First Search

Prefer interfaces to implementations public static ArrayList<State> findNeighbours(State currentState) { Consider ...
mdfst13's user avatar
  • 21.6k
4 votes
Accepted

Sliding tiles solver in Python

Whether the code is well designed or not -- is hard to tell without using it. But I have several points: It's good that you have small functions/methods which do one thing and do well. It's good that ...
warvariuc's user avatar
  • 337
4 votes
Accepted

Revised - Game of Fifteen

Functions that do not modify the referenced data should be made const to indicate that in fact, the code does not change things. It also allows some optimizations, ...
chux - Reinstate Monica's user avatar
4 votes

Game of Fifteen - A Sliding Puzzle Game

Bug - Valid Move Your valid_move method has this comment in it. ...
forsvarir's user avatar
  • 11.7k
4 votes
Accepted

N-puzzle solver using A* with Manhattan + Linear Conflict

Bugs: A lot of memory is allocated (foo = new Container) and never deallocated (delete foo). N-puzzle implementations usually ...
user673679's user avatar
  • 11.8k
4 votes

N-puzzle solver using A* with Manhattan + Linear Conflict

Platform-dependent code There's no need to bring in <Windows.h> - with a couple of small changes, this can be portable C++, accessible to everyone: ...
Toby Speight's user avatar
  • 77.1k
4 votes
Accepted

Npuzzle solver using A* with Manhattan + Linear Conflict (Updated Code)

Good job refactoring. It looks much neater without the globals / Manager class. Good effort with cleaning up allocated memory, but we can do better (see below). The ...
user673679's user avatar
  • 11.8k
4 votes

Optimizing the code for 8-puzzle in Python

Here are a couple of points: You need to move your documentation and your comments into docstrings: ...
aghast's user avatar
  • 12.4k
4 votes
Accepted

N-puzzle solver using A* search

Advice 1: l_moves The name l_moves is ain't good at all. Consider numberOfMoves. Since it ...
coderodde's user avatar
  • 28.7k
4 votes
Accepted

State space search for sliding tile puzzle

The initial approach definitely has a number of "bottlenecks" and space for optimizations. Let me present and explain the crucial points: starting with good naming: don't give Python identifiers/...
RomanPerekhrest's user avatar
4 votes
Accepted

Solving 15Puzzle with Julia

That was a fun exercise to work on! I completely refactored the code; the basic complexity issue Marc mentions still holds. I recommend this blog post for the cartesian indexing tricks. ...
phipsgabler's user avatar
4 votes

Simple N Puzzle console game

I have a few scattered observations. Your Tile.Value is a field rather than a property. If using a public access modifier, you ...
Rick Davin's user avatar
  • 6,360
3 votes

Revised - Game of Fifteen

I like the improvements you've made, so I've only got a few mostly cosmetic points: I don't like dim as a variable name. I think it's probably a hangover from ...
forsvarir's user avatar
  • 11.7k
3 votes

Revised - Game of Fifteen

More helper function Maybe the following piece of logic (in a least 4 places): game->board[get_row(i, game->dim)][get_col(i, game->dim)] could be ...
SylvainD's user avatar
  • 29.2k
3 votes

SDL2 Game of Fifteen / Sliding Puzzle

Overall it is good quality. I only have these complaints: ...
amchacon's user avatar
  • 156
3 votes

8puzzle solver using A*

Your A* is incorrectly implemented You are using the total number of moves explored as the priority for each search node. See here: ...
Emily L.'s user avatar
  • 16.6k
3 votes

Command line sliding tile puzzle in C++

Here are some suggestions that may help you improve your code. Be careful with signed and unsigned In a few places, the code compares an int ...
Edward's user avatar
  • 66.5k
3 votes
Accepted

15 Puzzle Game JavaScript

Foreword Your code is quite decent. However, I did make a general outline of how I would probably implement a Board to improve readability. Don't feel the need to ...
Neil's user avatar
  • 421
3 votes
Accepted

(Leetcode) Sliding puzzle in Python

Many great ideas here: using a hashable data structure to be able to store it in a set using a dequeue to generate the various possible states storing the neighboors in a dictionnary However, ...
SylvainD's user avatar
  • 29.2k

Only top scored, non community-wiki answers of a minimum length are eligible