Ashish Schottky

Ranch Hand
+ Follow
since Dec 29, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ashish Schottky

Thank you all for taking time to reply my question.
Here is what I was able to do, its simple tic-tac-toe problem, I have coded it using java swing, It will be great if you guys can play it and find flaws in it, also I would like you all to rate this and suggest improvements and also that I have just began to code swing.
Thank you.
applet
12 years ago
I am new to Java Swing.

I am writing some simple swing programs which use null layout.
I want to get feel of swing, how to position them. I had rough time with Layouts, so tried using null layout.
As I am going to make this as an applet, I don't think that it is going to bother me much on resizing issues, please correct me if I am wrong or I am missing something.

My first code was to just fill up a rectangle, leaving 10px on each side.
Here is my code.

//My main class, which handles the visibility of the class, it doesnot involve any logic.



My second class contains the control panel, that is buttons, and over all display.


Here is my third part, where the it draws the figure.
I kept it all three differently because I wanted them to be independent of each other and my code doesnt become one lengthy mess.


I am confused with the setBound method.
I have set the size to be 500x500.
I have used setBound(10,10,480,480)
Doesn't this mean that I should get an rectangle filling the entire area of 480x480 and leaving 10px border on each side?
this is how I visualized

But rather I am getting this(image attached).
Its leaving proper 10 px from left and top, but then it covers more than the allowed area and doesnt give the visualized look.
What am I missing here?

12 years ago
Here is a puzzle that is solved by hidden singles alone.
{ {1,0,0, 2,0,0, 3,0,0},
{0,2,0, 0,1,0, 0,4,0},
{0,0,3, 0,0,5, 0,0,6},
{7,0,0, 6,0,0, 5,0,0},
{0,5,0, 0,8,0, 0,7,0},
{0,0,8, 0,0,4, 0,0,1},
{8,0,0, 7,0,0, 4,0,0},
{0,3,0, 0,6,0, 0,2,0},
{0,0,9, 0,0,2, 0,0,7}};

I used the following strategy, a candidate 'x' that has only one cell to go and other candidates have legal possibility to occupy that cell, then candidate is said to be the hidden single.

I used this strategy to solve.
1) First pencil up the candidates.
2) Check for naked singles.
3)Update the candidates.
4)Check for hidden singles.

To check for hidden singles, just try if a candidate can occupy more than one cell that row and column, then it is not hidden, else its hidden candidate.
12 years ago
@Everyone : First of all I thank you all for taking out sometime to help me.


@Stephan van Hulst: No I havent read that, but when I started programing, I used complete-reference java.

@Bear Bibeault: I agree, but until I posted this, I was confused and didnt know what to do. I was just learning to swim by jumping in well, without any life-guards or floats. Thus I wanted to get my programing on the right foot. What bothered me was the bad practices which I kept on developing.

@Hebert Coelho : this is in reference to your first post, I am trying to get into graduate CS course, but I don't want to be a programmer all my life, I want to explore new areas in field of CS.
It also depend on what job I get and what they tell me to do.
I have just browsed through the reference you gave, seems to be quiet a nice one. Thank you.

@John de Michele : I am trying my hands on it currently, I am using Introduction to Algorithms (CLRS) to study algorithms. I am finding it hard to digest, can you suggest anything else some simple book on algorithms, it will be helpful.


So now I think I have to read effective java and the clean code first, then data-structures and algorithms based on java.
Thank you.

Thank you.

12 years ago
I am already 23 and I am developing javaSE from past 2 years, yet I am not very much comfortable programing in general.

Actually I am having trouble to implement algorithms or somethings like 'developing logic'.
I drew up a conclusion that I need to focus more on algorithms, but some how I am quiet weak in it.
Apart from my regular courses, I am self trained java programer by programing approximately 2hours a day.

I tried my hands on code-chef and project euler.
Solved about 40 problems now from project euler.

And many more coding problems, I developed board games, but I always used the inefficient method, and its a bad habbit that I cant get rid off.(eg, using dynamic memory allocation in AI, slows down the speed tremendously).

I neither do have formal back-ground in mathematics nor in computing, but I wish to be a good programmer, I am willing to put up my efforts, can anyone guide me how to be a better programer?
-Thank you.
12 years ago
@OP:
The best way I think, is to make few console apps, get used to few things in java, how objects work,inheritance,encapsulation,multi-threading. Once your hand is set on these, jump into GUI programing as it requires these basics.I think you should start from here.
12 years ago
@Padda: Welcome to Ranch.

When you build any board game, its generally better to keep separate classes for organization ,search,evaluation.

I suggest you to write a clean 2-player game.
Then make the AI component by allowing it to play random. This will test for legal moves in a position and winning combinations.
in connect four, winning is simple, so make another fuction, let it return some value if any player has won, this is your maximum score, and in game like connect4, this is what we want to achieve.

Then make sure you would add in more sophisticated search algorithm like min-max. Here I would like to suggest you that you go for a better frame-work of min-max namely "nega-max".
Once you get this working, then add in alpha-beta pruning , PVS or what ever you feel like.


Answer for your 1) ::

Computer in normal min-max search will compare all the scores
say best_move has score +5 and move B will have score +7 then best_move's score will be assigned as 7 and best_move now will be move B.

However, addition of alpha-beta changes the things quickly.
By adding alpha-beta, search doesnt evaluate all nodes(moves), thus it is faster than naive min-max.

Answer for your 2) ::

It differs from programer to programer. In general and widely used basic data-structure are arrays.
Arrays is java are certainly faster than Strings.

If you think further, assuming your game is for 7x6(standard board), there are only 42 cells.
long type in java offers uptil 64 bits, here you can allot 1-bit per cell so that takes only 42 bits.
This is a complicated approach but would be very fast. However I suggest you not to take this approach on first go, make a working connect4, then optimize it.

I hope this is not home-work.

If you want me to help you, then let me know so that I can write on it.
12 years ago
Thanks for replies.
I am still not able to decide if this way of coding is a normal form in C/C++ and not a bad practice.
I am asking this,because if this is possible, then I don't really find a good reason to get involved in pointer arithmetics and other pointer relates stuff.
So there has to be some advantage by using pointers, maybe speed or maybe avoiding memory leaks can you guys please help me with this?

Is there any other way which I can do it.
12 years ago
I am begining with C these days and I am cool with it.
I understand the concept of pass by value and pass by reference.
In pass by reference, one directly makes changes to the contents using the address.

Take a look at the code below.

In this, I havent used call by reference,yet the contents of the main array changes.
I have no explanation for this. Is this some bad programming practice?
If yes then kindly show me how to get it the correct way.

This is a snippet which I wrote and I am not quiet sure how it works,but it does.
please help.
12 years ago
@Mich: I am very busy currently and hence donot have anytime for chess programing.
I have "paused" developing chess long back.However once I get some time, I am planning to rewrite the code in C.
But for sure it wouldnt be anytime soon.

The links you posted are too awsome.
12 years ago
@Hama Kamal: I have been programing in Java from 2 years.
However I my main inclination was to program board AI-games.
I want to appear for SCJP and hence want to study.
However I am experiencing problems as I don't know how to organize my study and the time that I should allot per day to crack SCJP with a real good score.
Can anyone help me doing it,
I own a copy of SCJP 6.0 by K&B.
I want to appear for the exam in comming December.
Kindly help me in preparing time table for the same.
Help is form of "Allot minimum x hrs a day, prepare notes like this, refer following online websites"
is really appreciated.

Thank you.
@shibashish: AWT stands for Abstract Window Toolkit. It contains a class called as Component. This class contains a method 'Paint(Graphics g)', this paint method is used to update the screen.
eg: Display a message on screen, this will be done with help of paint method.
12 years ago
I dont know if this answers your question, but I find your while loop never terminates.
12 years ago
@Khair: You can do something like this:

Create a database /look up table sort of thing for morse<->english
say something like this.

Take the input as a string.
use a counter to count '|' from the current position, make a substring
search for this substring in morse code array,once found, printout the character from corresponding english array or put that in string.
in this way, you can eliminate the if statements for both types of conversions.
12 years ago