Tuesday, January 12, 2016

Saturday, August 2, 2014

Automatic Email Files Downloader


This is a software i created because i wanted a way to download files for backup. This program makes it easy for you to download any files just by emailing the link to an email account. The program downloads the file whenever the computer is on and it happens in the background. In the middle of download if the computer is shut down then it resumes back when the computer is on. So, it is kinda like dropbox but the goal is download not upload. I have provided both the source and executable jar below. Please be advised that you need jre 1.7 or later installed on your computer to be able to run the executable jar file below.


AutomaticEmailFilesDownloader

AutomaticEmailFilesDownloaderSource





Friday, June 27, 2014

Line Shooter



Unfortunately i couldn't complete the tower defense game because the artist left in the middle of development. So, i have ended the project for now with a working simulation that shows enemy and player combat which i have uploaded. This is a new game i finished recently. I have always been a fan of vertical scrolling shooters. My motivation for this game came after this game

M.U.S.H.A


So, in the lack of art i used lines to create art for the units.

The game is available here. Also included in the link is a level editor. Please read the documentation to understand how to create levels for this game.

Line Shooter

Line Shooter Source



Sunday, May 4, 2014

Sunday, March 30, 2014

Marriage Card Game Update



The card game i was working on is complete. Because of issues related to java certification in browsers i have not uploaded it in the web so the game is available as a stand alone only at this point. Please let me know if you know the game and/or are interested in playing. The server is running on the cloud. Since the certificate is not cheap i don't know if i should buy the certificate or make it available as a stand alone. Anyways, I have really enjoyed working on this game over a period of about 3 months. There were many challenges but my passion for the game overcame all challenges one by one. At one point I had a terrible bug which crashed the whole system. If i hadn't created backup copies, which were duplicates all over the desktop, then i would have to suffer. I now understand the importance of a version control system so i will definitely be using a version control software for my future projects. The advantages i see of using a version control over just plain project in desktop is version control avoids duplicate copies of your project and secondly it is easy to revert back to earlier commits without the risk of crashing the whole project because of an obscure bug that you don't seem to find. Anyways, this was a happy end to a chapter, a game that i really enjoy playing. A new chapter has started.  I created an animated gif to show the operation of the game. For the complete rules of the game, please follow the link below.


http://www.pagat.com/rummy/marriage.html











Saturday, February 15, 2014

Matrix Search



Given a sorted row and column matrix, find if it contains an element?

#include <iostream>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cassert>

using namespace std;

/*

1   2   3   4  
6   7   8   9
11 12 13 14
16 17 18 19


1   2        3   4  
6   7        8   9

11 12      13 14
16 17      18 19


We cut the matrix into 4 blocks at the center. We check the center element. If that is the element we are looking for, we return true else we do the same recursively in those 4 divided blocks. If the number is less than the top left most element in the block and greater than the right bottom most element in the block, we can return false since the element doesn't belong to the block.

*/

//My implementation
bool findElement(int ** nos, int r1, int c1, int r2, int c2, int no ){

    if(r1 > r2 ||c1 > c2) return false;
 
    if(no < nos[r1][c1] || no > nos[r2][c2]) return false;
 
    int mid_r = (r1+r2)/2;
    int mid_c = (c1+c2)/2;
   
    if(nos[mid_r][mid_c] == no) return true;
   
    return  findElement(nos, r1, c1, mid_r, mid_c, no) ||
            findElement(nos, r1, mid_c+1, mid_r, c2, no) ||
            findElement(nos, mid_r+1, c1, r2, mid_c, no) ||
            findElement(nos, mid_r, mid_c+1, r2, c2, no);
 
}


void sortRows(int ** nos, int row_size, int col_size){
    for(int i=0;i<row_size;i++){
            sort(nos[i], nos[i] + col_size);
    }
}

void sortCols(int ** nos, int row_size, int col_size){

    vector<int> list;
   
    for(int i=0;i<col_size;i++){
   
        for(int j=0;j<row_size;j++){
       
            list.push_back(nos[j][i]);
       
        }
        sort(list.begin(), list.end());
 
       for(int j=0;j<row_size;j++){
       
            nos[j][i] = list[j];
       
        }

        list.clear();
   
   
    }

}




class Array{

public:

int ** arr;
int row_size;
int col_size;

};



Array getARandomArray(int size_cap){

    int row_size = rand()%size_cap + 1;
    int col_size = rand()%size_cap + 1;


    int ** nos = new int*[row_size];
   
    for(int i=0;i<row_size;i++){
         nos[i] = new int[col_size];
    }
 
    Array toreturn;
    toreturn.arr = nos;
    toreturn.row_size = row_size;
    toreturn.col_size = col_size;
   
    return toreturn;

}




int main()
{
 
int value_range = 5000000;  //Value range of elements in the matrix
int total_tests = 100000;   // Total tests to be performed

int array_size_cap = 1000; // The generated array will have 1 <= row, col <= 1000


for(int t=0;t<total_tests;t++){

   
    Array tempa = getARandomArray(array_size_cap);
   
    int ** nos = tempa.arr;
    int row_size = tempa.row_size;
    int col_size = tempa.col_size;
   
   
    //Assign random values in value range
      for(int i=0;i<row_size;i++){
          for(int j=0;j<col_size;j++){
         
                nos[i][j] = rand()%value_range;
     
          }    
      }


    //pick a random element at random spot in the array
    int rand_item_row = rand() % row_size;
    int rand_item_col = rand() % col_size;
   


    //sort the array row and column wise
    sortRows(nos, row_size, col_size);
    sortCols(nos, row_size, col_size);
   
   
    //check if the algorithm finds that element
    assert(findElement(nos, 0, 0, row_size-1, col_size-1, nos[rand_item_row][rand_item_col]) == true);
     
   
    // free dynamically allocated memory
    for( int i = 0 ; i < row_size ; i++ )
    {
        delete[] nos[i]; // delete array within matrix
    }
   
    // delete actual matrix
    delete[] nos;


}


cout << "All tests passed ... "  << endl;
 
   
   return 0;
}

Saturday, February 8, 2014

Sudoku Solver





#include <iostream>

using namespace std;


bool isValid(char arr[][9]){
    
    //checking if each row has unique elements
   
    for(int i=0;i<9;i++){
        
          int temp[9] = {0};
          
         for(int j=0;j<9;j++){
        
            if(arr[i][j] != 0)
               temp[arr[i][j]-1]++;
            
        }
        
        for(int k=0;k<9;k++){
        
            if(temp[k] > 1) return false;
        
        }
        
    
    }
    
    
    //checking if each column has unique elements
    
    
    for(int i=0;i<9;i++){
    
        int temp[9] = {0};
                
        for(int j=0;j<9;j++){
        
            if(arr[j][i] != 0)
                temp[arr[j][i]-1]++;
            
        }
        
        for(int k=0;k<9;k++){
        
            if(temp[k] > 1) return false;
        
        }
    
    
    }
    
    
    
    //checking if each 3x3 have unique elements
    
    
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
                
            int temp[9] = {0};
                
            for(int k=i*3;k<(i*3+3);k++){
            
                for(int l=j*3;l<(j*3+3);l++){
                
                    if(arr[k][l] != 0)
                        temp[arr[k][l]]++;            
                
                }          
            
            }
                
            for(int k=0;k<9;k++){
        
                if(temp[k] > 1) return false;
            
            }
        
        
        }
    }
    
    return true;  

}



bool isSolved(char arr[][9]){

    for(int i=0;i<9;i++){
    
        for(int j=0;j<9;j++){
        
            if(arr[i][j] == 0) return false;
        
        }
        
    }
    
    return isValid(arr);


}




int values_tried = 0;
bool solved = false;


void solveSudoku(char arr[][9]){


    if(!isValid(arr)) return;

    if(isSolved(arr)){
    
        for(int i=0;i<9;i++){
           for(int j=0;j<9;j++){
               cout << (int)arr[i][j] << "  ";
            
            }
           cout << endl;
       }
  
        cout << "This many values tried " << values_tried << endl; 
        
        solved = true;
        
        return;
    
    }

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////TRY 1-9 VALUES FOR EACH CELL AND CHECK FOR VALIDITY RECURSIVELY/////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


    for(int i=0;i<9;i++){    
        for(int j=0;j<9;j++){
               
            if(arr[i][j] == 0){
        
                //Trying all values 1-9 for each cell
                for(int k=1;k<=9;k++){
                        
                    values_tried++;
                    arr[i][j] = k;
                    
                    solveSudoku(arr);
                    
                    arr[i][j] = 0;
                
                }
                
                //1-9  didnt work so backing out  
                return;
            
            }
       
            if(solved) break;          
       
        }

        if(solved) break;

    }
}





int main()
{


char arr[9][9] = {

{8, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 3, 6, 0, 0, 0, 0, 0},
{0, 7, 0, 0, 9, 0, 2, 0, 0},
{0, 5, 0, 0, 0, 7, 0, 0, 0},
{0, 0, 0, 0, 4, 5, 7, 0, 0},
{0, 0, 0, 1, 0, 0, 0, 3, 0},
{0, 0, 1, 0, 0, 0, 0, 6, 8},
{0, 0, 8, 5, 0, 0, 0, 1, 0},
{0, 9, 0, 0, 0, 0, 4, 0, 0}

};


solveSudoku(arr);
cout << "Done" << endl;
return 0;
}





Output: