Code Monkey home page Code Monkey logo

bb4-simulations's People

Contributors

barrybecker4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

bb4-simulations's Issues

Trebuchet enhancements

Goal: optimize the structure in the simulation, the build physical lego trebuchet based on it.

  • draw the trebuchet offset from the bottom, not the top - so we can see the arc of the projectile better (done)
  • draw a trail for the arc of the projectile - to see it better (done)
  • separate model from renderers (done)
  • zoom out when firing so that the whole arc can be seen (done)
  • the projectile should land/stop when it hits the ground (done)
  • add dynamic options for things like numStepsPerFrame and all the sizes and ratios (things currently in options)
  • measure the distance that it traveled and display it. This will be used to measure the fitness when optimizing (done)
  • apply the optimize library to iteratively optimize a solution
  • print the optimized params
  • build Lego structure based on the result

add auto-fit to LSystems

When checked, the tree should auto fit to the dimensions of the screen when parameters are changed. Also the scale scrollbar should probably be disabled.

DungeonGenerator

Use PCG (Procedural Content Generation) to automatically generate rooms in a dungeon.
Inspired by my son's work in hi pixel-perfect game that he wrote in C#.

Implementation will proceed in these phases:

  1. Use binary space partitioning algorithm to generate randomly placed rooms.
    • rooms will be nodes within a graph. Each node will have properties for hight, width, xpos, ypos, color, connections.
  2. Have parameters that control how the rooms look. Changing these parameters generates a new map.
    • min/max room width
    • min/max room height
    • Percent filled. 1% means just one room, while 100% means completely filled with rooms
    • border - space between room and rectangular cell border
    • color
  3. Add hallways between rooms. All rooms need to be connected in some way.
    • first connect all adjacent rooms
    • then gradually increase the distance until room for a connected graph
    • hallways will be represented by properties for room1, room2, pathPoints.
  4. Optionally add long hallway as node between partitions. It will be a node in the graph, like rooms, but be a long halway.
  5. Add items and other decoration
  6. Add support for multiple "Biomes", where a biome controls what parameters are used to create rooms, hallways, and items within a region of the dungeon (biome).

WFC: more robust

Currently, the runs fail too easily resulting in a black screen.
Either they should not fail or they should fail with more diagnostic/visual information about why they fail.
Maybe some constraints ca be relaxed so that they can be allowed to proceed with minor inconsistencies.

In habitat sim, add tabbed panels for animal props in UI

The controls on the right should be organized into tabs where each tab has the controls for one of the animals.
The tab title should have the name of the animal and an icon representing it.
Add a span button to add mroe of something in case it goes to 0.
e.g.
add [5] - if too few
kill [4] - if too many

WFC: add concurrency and or backtracking

Since the algorithm fails often, we could run simulations in parallel and take the first one that succeeds.
Another option to avoid failure might be to run until failure, then progressively backtrack until a solution can be found (if it is possible).

Use union-graph strategy to generate random dungeon

Union Graph Strategy

Find Rooms

  1. Start with a dungeon space of size M*N. Add this space to a priority queue (prioritized by area).
  2. Pop an area off of the queue. Select a random room within that area.
  3. Subtract the area of that room from the remaining total.
  4. Divide remaining area into rectangular candidate regions that are as square as possible and add them to the queue. Only add them if it is possible for them to contain a room.
  5. Repeat at step 1 until the desired proportion of space is filled.

Create Cell Map

  1. Create a 2D grid of cells. Each cell will map to a room, a corridor, or nothing

Find corridors

  1. Every room represents a graph in a set of graphs. Each of those graphs identifies a set of nodes (nodeset). The corridors will represent the edges in the graph.
  2. Pick 2 nodesets A and B that have the fewest members. Put the nodesets on a priority queue so that we can always get the 2 with the fewest members by popping them off of the front. A nodeset should know its bounding box. Whenever sets are merged, that bounding box will grow. Select room AA from A that is closest to the bounding box of B and room BB from B that is closest to the bounding box of A.
  3. These 2 rooms define a square within the grid.
  4. March from each node toward one of the 2 possible intersection points (the other 2 corners).
  5. There are a few cases that can happen:
  • If there is nothing in the middle, these 2 paths will join at the corner and form a corridor between the 2 rooms.
  • A path front (or part of the path front) hits a room. Use the cellMap to tell what was hit. If it just hits the edge, reduce the width of the path and continue. If it solidly hits the middle, select one of the lines of cells other than at the edge. That way we can be sure that there will be at least a one cell buffer between the corridor and rooms.
  • A path front hits a corridor. We can tell what is hit using the cellMap created above. In this case, select one of the lines that hit the corridor and add this segment to that corridor. In doing that we may join 2 trees (sets) if the ancestors are different. That corridor adds the source room to its list of connected rooms, and the room adds that corridor to its list of connected corridors. If the original node does not share the same root as the nodes joined by the corridor, then the roots of the 2 trees are joined to form a larger tree by adding a new root with the 2 trees as subtree children.
  1. Repeat from step 2 until everything is connected.
  2. If there are too many leaf rooms, or not enough connectivity, then we can optionally add more connections by selecting pairs of nodes from among those with the fewest connected corridors.
  3. If there are not enough leaf rooms, we can optionally add more leaf rooms now, by filling in the remaining empty spaces. Note: the queue still has the remaining empty regions. Create a room in an empty space and connect it to something nearby by sending out lines from the 4 sides until he first hits something. It might get connected automatically if it gets placed on existing corridors (likely). If this happens, those corridors should get split into smaller ones so that no corridor is under the roo,

WFC: NPE for Flowers model

I often get a stack trace like this

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at com.barrybecker4.simulation.waveFunctionCollapse.model.wave.Wave.doPropagation(Wave.scala:147)
	at com.barrybecker4.simulation.waveFunctionCollapse.model.wave.Wave.propagate(Wave.scala:139)
	at com.barrybecker4.simulation.waveFunctionCollapse.model.WfcModel.$anonfun$advance$2(WfcModel.scala:65)
	at scala.collection.immutable.Range.foreach$mVc$sp(Range.scala:190)
	at com.barrybecker4.simulation.waveFunctionCollapse.model.WfcModel.advance(WfcModel.scala:59)
	at com.barrybecker4.simulation.waveFunctionCollapse.model.WfcModel.runWithLimit(WfcModel.scala:43)
	at com.barrybecker4.simulation.waveFunctionCollapse.model.WfcModel.startRun(WfcModel.scala:49)
	at com.barrybecker4.simulation.waveFunctionCollapse.DynamicOptions.runModel(DynamicOptions.scala:248)
	at com.barrybecker4.simulation.waveFunctionCollapse.DynamicOptions.itemStateChanged(DynamicOptions.scala:261)
	at java.desktop/javax.swing.JComboBox.fireItemStateChanged(JComboBox.java:1227)
	at java.desktop/javax.swing.JComboBox.selectedItemChanged(JComboBox.java:1279)

Add WaveFunctionCollapse simulator

Add scala port of code (done)
Add new simulator
Refactor and make clean

  • more model classes
    Add param panel so that we can pick a single configuration and watch it run in the simulator explorer
  • select image file or directory (for simpleTiledModel)
  • set size
  • set constraints
  • visualization strategy
  • speed
    Extract out to separate library repo
    Consider 3D models

Consider making this interactive version in the explorer
WebGl 3d version.

DungeonExplorer: organic generator strategy

So far I have "bsp" and "unionGraph".
The next idea to implement is "organic".
For this approach, we will start with one room and then sprout other connected rooms out from it until the available dungeon area is completely filled. Additional connections, besides just those to the root, can be added as we go depending on the value of the connectivity param. This approach will have a couple of advantages:

  • it can fill any available space, not just a rectangle
  • its guaranteed to be linear time with the number of rooms
  • it should fill gaps very well, however, not sure how to handle the percentFilled param yet

Here is the general approach:

  1. Start with an initial randomly sized and placed room. Add 4 corridor points to a queue corresponding to the 4 sides.
  2. pop a sprout point off of the queue until there are none or the space is filled.
  3. find a space for a connected min sized + 2 room next to it.
  4. Determine a target size for that adjacent room. Grow that adjacent min-sized room until it reaches that target size +2 or hits a block (another room or corridor. Once one of those 2 things happens, backup by 2 cells to establish the new room dimensions.
  5. If a room was established, add 3 sprout points corresponding to 3 remaining sides to the queue. If a dimension is long, maybe add more than one connection point.
  6. If there is not even space for a min-sized room, depending on the connectivity thresh, create a corridor if possible.
  7. repeat from step 2 until nothing left in the queue.

longer snake

The current snake is pretty short. It would be nice to have some longer versions.

IndexOutOfBounds when changing colormap in FractalExplorer

Exception in thread "Thread-18" java.lang.IndexOutOfBoundsException: Index: 6, Size: 6
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at com.barrybecker4.ui.util.ColorMap.getColorForValue(ColorMap.java:60)
at com.barrybecker4.simulation.common.rendering.ModelImage.updateImage(ModelImage.java:72)
at com.barrybecker4.simulation.fractalexplorer.FractalExplorer.timeStep(FractalExplorer.java:119)
at com.barrybecker4.ui.animation.AnimationComponent.run(AnimationComponent.java:91)
at java.lang.Thread.run(Unknown Source)

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.