Tuesday, March 27, 2012

Stormy

This one comes from Katie in a family email chain, back we had sheep and I was just a wee ladie. I don't know why we but the bugger on the wagon.
Top: Matthew, Esther, Father, Samuel. Bottom: Isaac, Samuel, David (bike helmet),Matthew

Sunday, March 25, 2012

Battleship - Game Play

I found out today that someone else did something similar to what I did: http://thevirtuosi.blogspot.com/2011/10/linear-theory-of-battleship.html, but we are a little bit different.

I calculate what happens with a miss by passing a board where that is an imaginary ship - place all of the ships, and then subtract off the imaginary ship board before returning.  I also changed the order in which I place the ships; placing the larger ships first makes it not take as many searches to find a space where a large ship would fit.

Effects of misses (right) on the (left) PDF.  A miss means that a ship cannot be there so the PDF at that location must be zero.
Anyway, I have the rest of the code written but haven't made any visuals of it.  It is essentially just computing the PDF, and then choosing from that PDF for where to place the ships.  It gets a little bit hung up on deciding what ships are remaining; currently I keep on assuming that I don't eliminate any ship until they all are sunk.

In the event of a nuclear disaster don't "Eat Fresh, Eat Local".   And try not to breathe the air.  You get about 500 times more dose* if you eat contaminated food.  Especially don't drink the milk 2 days after the event.


*depending on what sort of isotope, etc.

Thursday, March 15, 2012

Battleship Ship Placement - Part II

Previously I showed numerical PDF's for the placement of a ship. Now I am going to attack the analytical solution.

I'm defining the PDF as the possibility that a shot taken at a particular (i,j) coordinate on the board could result in a hit.  The simplest example is at a corner because there can only be two ships there.

 For a two by 1 ship the possible number of ships at a given (i,j) are laid out in the following image.
The probabilities are then: For a two by 1 ship the probabilities are:
These were tabulated up to the size of the ship, after that it repeats. For a ship of length two:

For a ship of length three:

 For a ship of length four:

 For a ship of length five:

 
The next issues is what happens to the PDF once we take a shot.

Tuesday, March 13, 2012

Battleship (Ship Placement)

The idea is to find the optimal game play of battle ship; one that ensures the minimum number of loses - because of the random nature of the game (not knowing where the opponents ship's are) it is impossible to ensure a win.

Naive Ship Placement
I then wanted to find a probability density function (PDF) from which to pick my positions; want to sample (take more shots) more where there are more shots. This was first approached numerically and then analytically.  The numerical PDF's were calculated by creating 1 million boards and summing them, and then averaging for the number of boards run (1 million).  Ships are placed anywhere on the board under the following conditions:
  • The ship is continuous
  • Another ship is not present
  •  Entire ship fits on the board
The key point in implementation is that it is only necessary to implement ships placement in one orientation, and just transpose the board to for the other orientation.  The board is simply an (n x n) logical array, where the true (1s) mark the locations of ships.
PDF of ships of length [2,3,3,4,5] being placed on a 10x10 board
 We observe that as less ships are added (ignoring the aircraft carrier of size 5) that the PDF flattens more.
PDF of ships of length [2,3,3,4] place on a 10x10 board
These are not true PDF because they are not normalized to 1, but rather to the amount of ships; i.e. the board of ships [2,3,3,4,5] would sum to 17.

Analytically this was approached by counting the number of ways to arrange a ship of a given size on the board.  All possible combinations are worked out for ships of size 2 and 3.
Possible placements of ships of size two, 9 total.
Possible combinations of ships of size three. 17 possible combinations.
 Given a position (i,j) on the board, we can then calculate  (analytically) the probability that a ship will be placed there, but that will have to wait for tomorrow.

Code for generating Boards:
 function [board] = generateBoard(obj)
            % Allocating space for the board
            board = zeros(obj.n,obj.n);

            i = 1;
            while i <= numel(obj.ships)
                ship = obj.ships(i);

                % Determining Orientation
                ort = (rand>0.5);

                % Determining Position
                x = randi(obj.n);
                y = randi(obj.n);
                shipEndPoints = [x x+ship-1];

                % Placing Ship, if it is a valid position
                if canPlaceShip(obj,shipEndPoints,y,board,ort)
                   board = placeShip(shipEndPoints,y,board,ort);
                   i = i +1;
                end
            end
        end 
end 
function validPosition = canPlaceShip(obj,shipEndpoints,col,board,ort)
if ort;
    board = board';
end
% Logical Values for Board Placement
if (shipEndpoints(1) >= 1 && shipEndpoints(2) <= obj.n) && (0 == sum(board(shipEndpoints,col)))
    validPosition = true;
else
    validPosition = false;
end
end
function board = placeShip(shipEndpoints,col,board,ort)
if ort;
    board = board';
end
% Spots are now filled
board(shipEndpoints(1):shipEndpoints(2),col) = ones(abs(diff(shipEndpoints)+1),1);
% Need to Flip Back
if ort;
    board = board';
end
end

Thursday, March 8, 2012

Talking Atom

Some pretty nice lyrics.

Tuesday, March 6, 2012

MSR Ted Talk

I came across this Ted Talk of Kirk Sorensen talking about Molten Salt Reactors.  MSR's are great design reactors, but there are still many material issues that need to be addressed; mainly the heat exchangers and what salt is the best.  These breeder reactors, especially in liquid fuels, are also susceptible to proliferation (i.e. breeding U-235 and online processing to extract it).