I was thinking about creating minesweeper in python/pygame. However, I was stumped when I was trying to figure out a way to guarantee a large swath of empty space on the first move (such as in minesweeper on Windows XP). Does anyone have a method for doing this? I don't want code, just words.
Thank you in advance
Firstly, that doesn't happen on Windows XP (or any common minesweeper implementation) every time. It's very likely to if you are playing on a low difficulty though.
There are some ideas though;
Generate the map after the first click. This allows you to avoid the area the user clicked, giving you the large swath you desire - simply by tweaking your mine placement algorithm to avoid the area around where the user clicked.
Generate the map - but change it if insufficient space would be exposed. This will (probably) result in a faster reaction on the first click as the map will likely be already generated.
Don't do this. As mentioned previously - this is not how windows XP worked. But there was a high likelihood of this just happening naturally on easier difficulties. It might be worth recalculating the map if the user clicks on a mine on the first move, but otherwise leave it to your random distribution. Remember that (except some custom modes) there are going to be many more empty squares than ones with mines.
Hopefully that will get you started.
Related
Is there a way to have an image be created/drawn entirely without the actual Window that usually pops up when starting a turtle script showing up? The reason for this question is that while doing more research into another problem I posted here:
How to properly interact with turtle canvas/screen sizing?
I found that resizing the screen using maximize on the window actually altered what was capture when using .getcanvas() to be saved.
This wouldn't be a problem if I weren't attempting to create large images, larger than my monitors certainly. (around 15000 x 15000 pixels).
Thus I am wondering if there is a way to have the entire drawing process be done in the background. Without a window popping up at all. This way (I would hope at least) my images aren't becoming distorted or incorrectly sized due to buggy window interactions. As an example when I try to create an image this big, even with turtle.tracer(False) set it still flashes for a small amount of time (as the images are large and take time to complete) and while it is 'open' I cannot switch to it, it does not appear on my screen, it only appears on the task bar, which I can hover over and like with other applications 'preview' it without clicking on it, and it does not show there. However the image will be created and saved. But the dimensions are entirely wrong based on the code I used.
For a minimally repeatable example please look to the hyperlink to my related question. The code and subsequent image of that post is directly related to this question. But as the questions are different in nature I decided to create this post asking it.
Any feedback would be greatly appreciated as I cannot find any information in the documentation on how this might be done if it is possible at all. If anyone knows any good resources to directly contact regarding Turtle then that information would be welcomed as well.
I'm not sure if this will help to much but if you set the turtles speed to 0 then there will be no animation and the turtle will draw the picture instantly.
The code would look something like: turtle.speed(0)
WHAT: I'm looking for a way to create an f-curve to dynamically retime an arbitrary number of keys in Maya. Something like an Animation Layer, but for timing on a per-asset basis.
WHAT NOT: I've got a great linear retime-from-pivot script already. Used it for years, love it, not looking for that.
WHY: Lets say I've animated several goblins racing toward an enemy. Maybe they start the shot behind a gate or something because I don't want to change the timing of the start of the shot, and I don't want to change the end of the shot because I've already animated the hero striking them, and I can't change the length of the shot because the shot length is locked.
The director wants one of the goblins to get a little ahead while they are running, and then to slow back down into the current overall shot timing. This director is more of a "I'll know it when I see it" kind of guy so I expect several rounds of revisions, and he might throw in a stumble request later for all I know, so I want to be able to mute this retime (so I'm working on whole numbered keys) and have it non-destructive (no baking).
SUMMARY: So, I want to scale an arbitrary number of keys on a selected object by a gradient with an arbitrary start and stop for the retime that can be muted, removed, or adjusted non-destructively.
I'm thinking that setting an f-curve that will affect the timing of selected keys would be perfect. Exactly like how animation layers work, but for timing.
Bonus points if a single retime curve can affect keys on several animation layers, as well.
Is this idea possible? Can you point me in some good direction for getting started, or any tools that have already been written? I'm very new to learning programming, and am just starting to learn python for maya.
This should be possible. Have a look how a scene timewarp works. Every animation curve is connected to a time node. Usually you only have one time node which is connected to all anim curves. A scene timewarp is connected to this time node. What you can try is to create a time node for every bunch of animcurves you want control seperately. And then create a animCurveTT and connect it to the corresponding time node. If this precdure works, you can script it to make it easier to control.
I created A star algorithm visualization in pygame, and pygame window freezes sometimes (when algorithm is working), I know that this algorithm is not the most optimized one, but I think that the algorithm isnt causing this issue. Please help me, because its quite annoying, and i dont know what causes this issue.
Link to code -> https://github.com/DeathEyeXD/PythonProjects/blob/master/aStarVisualization.py
Please paste relevant part of the code here and show us what you have tried so far.
I assume that you have a main pygame loop running at a certain frequency. When you have a function calculating things in the main loop that takes a considerable amount of time, it will cause the game window to freeze. This is because it cannot reach other things (like your event function) at the same time as it is calculating the path.
With A* algorithm you can make it nicer by drawing the progress (draw the neighbors and checked cells for example). I did a project like this previously which works nicely. You then call your draw function within the A* function at relevant places and you won't get the freeze issue.
The question I have is, is it possible to run a Pymunk simulation without having the screen to visualize it pop up?
I'm working on a research project that involves Pymunk and Pygame. The goal is to develop an agent that can infer certain properties about physics simulations involving objects and agents within the Pymunk space.
Part of the project requires a comparison of many different simulations and the fact that a screen pops up so I can view each simulation causes the problem to take too much time (as I have to view each sim before being able to collect the data from it).
I'd like to basically run each sim in the background as fast as possible to just collect the physical data. There is no need for me to actually visualize the simulations at certain points.
Let me know if I've been clear enough or this is a duplicate. Though, I searched for an answer here, I have not found one.
Pymunk itself doesn't depend on any visualization. You move the simulation forward with the space.step method, and you can call it as many times as you want, for example 1000 times with a dt of 0.1 to move the simulation forward 100 units (seconds).
If you want to see something you have the option to read out the state and draw it at that time.
The pygame integration provided with pymunk is just for those that want an quick and easy way to get something on screen. If you don't want anything drawn you absolutely not need to use it.
Just be aware that it is not the same to call space.step 100 times with a dt of 0.01 and calling it with a dt of 1 (the later will give a much less accurate simulation)
I'm working on a Minecraft-style game, and I need a way to reduce the amount of the world rendered. Currently, I'm using a naive, render-everything approach, which is having obvious scaling problems. I need a way to take an array of blocks, and in some way find out which ones are touching air, water, or any other translucent block.
I'm open to using external modules like NumPy or SciPy, though some of their documentation is a bit over my head. Alternatively, it would also be acceptable to iterate through each block and get a list of neighbors, though the performance cost of doing these calculations in Python instead of C would be pretty hefty.
For the record, I've already tried looking at NetworkX, but it seems to be more for scientific analysis or pathfinding than visibility checking.
If you only need to do this once, performance should not be an issue. If you also incrementally update the .isBoundary property of blocks whenever the world is changed, you will never have to do it again.
However you still run into issues if your world is too large or full of holes and caverns and transparent-interleaved-with-nontransparent. If you need to dynamically determine what is visible, you can keep an octree ( http://en.wikipedia.org/wiki/Octree ) where you can have giant expanses of air/water/etc. as a single node (giant block), labeled as "transparent". Then use the "paintbucket" algorithm (modified to perform Dijkstra's algorithm, so it is easy to detect when you've "gone around a corner" by checking to see if blocks exist between the current block and the origin) to quickly figure out which blocks are in sight. Updates for things far in the distance can be delayed significantly if the player is moving slowly.
You could use the Z-Buffer solution. Concerning speed, I'd write as much as possible in python and use pypy. EVE Online (a successful 3D MMO) was written in stackless python I believe.