Two Plus Two Publishing LLC
Two Plus Two Publishing LLC
 

Go Back   Two Plus Two Poker Forums > >

Notices

Programming Discussions about computer programming

Reply
 
Thread Tools Display Modes
Old 09-07-2018, 01:17 PM   #1951
_dave_
_Pooh_Bah_
 
Join Date: Feb 2005
Location: UK (or what remains of it)
Posts: 12,778
Re: Programming homework and newbie help thread

Quote:
Originally Posted by d7o1d1s0 View Post
- Verify it's returning all my posts (102 for the first thread, know there's a way to check this on the forum but haven't found it yet)
In the forum index click the number of posts on the thread of interest, it gives you a list of all thread contributors and their post count.
_dave_ is offline   Reply With Quote
Old 09-07-2018, 01:24 PM   #1952
d7o1d1s0
See my coaching listing
 
Join Date: May 2010
Location: PGC
Posts: 2,357
Re: Programming homework and newbie help thread



yay!
d7o1d1s0 is offline   Reply With Quote
Old 09-14-2018, 07:55 AM   #1953
sheeprustler
veteran
 
sheeprustler's Avatar
 
Join Date: Jun 2009
Location: @sheeprustler
Posts: 3,242
Re: Programming homework and newbie help thread

I am learning java and I am practising making classes and methods.

I've created a method "question" method which I want person1 to call. I have no problem calling the method but it skips my first two if statements and goes to the default "Speak up".

Any advice is appreciated.
__________________________________________________ ____________________
package Tutorials;

import java.util.*;

class Person {
String name;
int age;
Scanner input = new Scanner(System.in);
String answer;

void question() {
System.out.println("Please say hello to our new robot friend");
answer = input.nextLine();
if (answer == "Hello") {
System.out.println("Hello yourself");

} else if (answer == "Hi") {
System.out.println("Queen's English please!");
}
}

void speak() {
System.out.println("Hello");
}

}
__________________________________________________ ____________

public class thirteen {
public static void main(String[] args) {

Person person1 = new Person();
person1.question();

}

}
__________________________________________________ ____________________
sheeprustler is offline   Reply With Quote
Old 09-14-2018, 08:45 AM   #1954
jjshabado
Carpal Tunnel
 
jjshabado's Avatar
 
Join Date: Jul 2006
Posts: 22,340
Programming homework and newbie help thread

Log what answer is after you collect it to make sure it’s what you think it is. In particular there might be newline characters or something there.

Also, Strings are objects in Java so you want to use ‘.equals’ instead of == so that you’re comparing the content of the string and not the object reference.
jjshabado is offline   Reply With Quote
Old 09-14-2018, 10:33 AM   #1955
ChrisV
Carpal \'Tunnel
 
ChrisV's Avatar
 
Join Date: Jul 2004
Location: Adelaide, Australia
Posts: 38,175
Re: Programming homework and newbie help thread

Quote:
Originally Posted by jjshabado View Post
Also, Strings are objects in Java so you want to use ‘.equals’ instead of == so that you’re comparing the content of the string and not the object reference.
Yeah this is going to be the issue. Usually you do it like

Quote:
if("Hello".equals(answer)) { ...
that's safer, because if you do if(answer.equals("Hello")) then it will throw a NullPointerException when answer is null (which it won't be here, but it's a good habit).

To expand on equality a bit more, in Java == does value comparison for primitive types. So:

Quote:
int x = 1;
int y = 1;
boolean areEqual = (x == y) //true
But for objects, == is a reference comparison. Object variables are actually pointers to a location in memory. == tests if they point to the same location. So:

Quote:
String x = "hi";
String y = "hi";
boolean areEqual = (x == y); //false
areEqual = (x.equals(y)); //true
y = x;
areEqual = (x == y); //true, because it's not just that they're both "hi", they're both the SAME "hi", at the same place in memory. y = x, for objects, says "point y to the same place in memory as x".
Other similar languages (like C#) make an exception for strings and do a value comparison for ==, but Java doesn't, basically because it's the mission of Java to be as pedantic as possible and make your life difficult.

Also, if you write your code in IntelliJ (which is free, for the basic edition), it will warn you about your dubious use of == and you can set breakpoints and debug to see the execution path your code is taking.
ChrisV is offline   Reply With Quote
Old 09-17-2018, 02:07 PM   #1956
leavesofliberty
Carpal \'Tunnel
 
Join Date: Jul 2010
Location: probably busto
Posts: 6,225
Re: Programming homework and newbie help thread

IPC question

What is the best way to store an array in shared memory with threading? Is it better to try to store the whole 2d array in shared memory as a 2d array, or try to cram it into 16 bits, and do the calculation in the threads. I am thinking about storing it in a 32 bit integer, and changing my look-up tables. Before I was doing base 3 with 16 bits. Thoughts?

Also, what about more complicated data such as structs? Thank you.
leavesofliberty is offline   Reply With Quote
Old 09-17-2018, 02:19 PM   #1957
well named
poorly undertitled
 
well named's Avatar
 
Join Date: Jun 2007
Location: esse est coesse
Posts: 74,581
Re: Programming homework and newbie help thread

I don't really follow what you mean by "cram it into 16 bits", but in general I would say it's not the size of the data that's an issue for shared memory, it's going to be how you synchronize access if multiple threads need to write, or if you need to ensure a particular order of events between threads. (i.e. let one thread finish writing before a second thread reads).

I haven't really done anything remotely like this in years, so I don't have much of a recommendation, but it might be useful to implement some existing library for managing this. There seem to be a few options, although which you prefer might depend on what platform you are targeting.
well named is offline   Reply With Quote
Old 09-18-2018, 12:02 PM   #1958
sheeprustler
veteran
 
sheeprustler's Avatar
 
Join Date: Jun 2009
Location: @sheeprustler
Posts: 3,242
Re: Programming homework and newbie help thread

Thanks for the answers
sheeprustler is offline   Reply With Quote
Old 09-19-2018, 05:29 PM   #1959
leavesofliberty
Carpal \'Tunnel
 
Join Date: Jul 2010
Location: probably busto
Posts: 6,225
Re: Programming homework and newbie help thread

I worked on it some more. There's nothing special you have to do to convert struct pointers to void pointers other than ordinary casting. Though you can shave bits with number theory and unsigned integers, it's premature optimization to do so at the beginning. It is better practice to use structs, and only after everything else is done, go back and improve it. Structs naturally use the compiler to limit the size of your data structure.

raw bits != friendly

Last edited by leavesofliberty; 09-19-2018 at 05:34 PM.
leavesofliberty is offline   Reply With Quote
Old 10-18-2018, 01:20 PM   #1960
fastriffs
centurion
 
fastriffs's Avatar
 
Join Date: Aug 2008
Posts: 119
Re: Programming homework and newbie help thread

My simple issue does not deserve a thread on its own so asking here. Im trying to write hot keys in python for playing(middle mouse button for fold etc). My script need to determine button was clicked on the table and act only then on that table. So when using:

hwnd=win32gui.WindowFromPoint(win32api.GetCursorPo s())

i get HWND of item under cursor, which can be a button handle or chatbox handle etc. I could manage with a makeshift solution here, but im looking for best one. All this windows terminology of properties of windows is really confusing(owner, child, parent etc)

So what im trying to achieve here is determining whether user clicked on a poker table, then determining its size in pixels. Does whole table frame has a HWND? How to get it from object HWND within a table?
fastriffs is offline   Reply With Quote
Old 10-18-2018, 03:43 PM   #1961
RustyBrooks
Carpal \'Tunnel
 
RustyBrooks's Avatar
 
Join Date: Feb 2006
Location: Austin, TX
Posts: 23,964
Re: Programming homework and newbie help thread

I had a little library that did something much like this, but I can no longer find the code for it.

Have you tried following the "parent" upwards until you get to a window that has a "title" that looks like what a poker window should look like?
RustyBrooks is offline   Reply With Quote
Old 10-18-2018, 03:56 PM   #1962
fastriffs
centurion
 
fastriffs's Avatar
 
Join Date: Aug 2008
Posts: 119
Re: Programming homework and newbie help thread

For now solved by using GetForegroundWindow(), but that works on mouse button release, as only then window jumps to focus, not on mouse press. Not optimal solution, but will do for now.

So lets say chatbox would be considered a 'child' and table Window would be considered a parent? I might experiment with that in future.
fastriffs is offline   Reply With Quote
Old 10-18-2018, 04:44 PM   #1963
RustyBrooks
Carpal \'Tunnel
 
RustyBrooks's Avatar
 
Join Date: Feb 2006
Location: Austin, TX
Posts: 23,964
Re: Programming homework and newbie help thread

Quote:
Originally Posted by fastriffs View Post
For now solved by using GetForegroundWindow(), but that works on mouse button release, as only then window jumps to focus, not on mouse press. Not optimal solution, but will do for now.

So lets say chatbox would be considered a 'child' and table Window would be considered a parent? I might experiment with that in future.
In general you can think of a Windows window as a collection of rectangles, with each rectangle optionally containing a collection of rectangles, all the way down. So each element has a single parent and may have multiple children. It's basically a tree. From any HWND you can examine your parent or see what your children are. You can usually get properties of a window from it's HWND - I don't know the python win32 implementation, just the C/C++ library so I don't know what all you can do

Not all windows have a parent - there's a special code that indicates that a window is toplevel but owned by another window - this is common for popup windows for example, they are a top level window, but they're considered part of another toplevel window. Windows that don't have a parent are usually toplevel windows.

Something else I used to do was use "AutoIt" which is a program that lets you script a lot of this stuff in a simple way. You can make autoit scripts and bind them to keys or mouse clicks, and back when I was doing this, at least, they had a C library that you could do so that you could embed their actions into your C programs. There are python bindings for autoit but I've never used them
RustyBrooks is offline   Reply With Quote
Old 10-18-2018, 06:09 PM   #1964
fastriffs
centurion
 
fastriffs's Avatar
 
Join Date: Aug 2008
Posts: 119
Re: Programming homework and newbie help thread

Thanks for clarification! Im doing this project mostly for my own education in python, so will stick to python instead of ready solutions. So i was doing pretty well untill i've hit a problem: My mouse events hook is not reporting any mouse events on tables while PT4 auto import/HUD is running. Im using this lib: 'https://github.com/boppreh/mouse'. There does not seem to be many alternatives to this one for python. Im pretty stuck for now.
fastriffs is offline   Reply With Quote
Old 10-18-2018, 06:54 PM   #1965
_dave_
_Pooh_Bah_
 
Join Date: Feb 2005
Location: UK (or what remains of it)
Posts: 12,778
Re: Programming homework and newbie help thread

That's probably a "run as administrator" thing.
_dave_ is offline   Reply With Quote
Old 10-18-2018, 07:12 PM   #1966
fastriffs
centurion
 
fastriffs's Avatar
 
Join Date: Aug 2008
Posts: 119
Re: Programming homework and newbie help thread

Ideed! Your valuable tip saved me alot of time. I would never have guessed this might be the issue.
fastriffs is offline   Reply With Quote
Old 10-18-2018, 07:36 PM   #1967
RustyBrooks
Carpal \'Tunnel
 
RustyBrooks's Avatar
 
Join Date: Feb 2006
Location: Austin, TX
Posts: 23,964
Re: Programming homework and newbie help thread

Huh, I wouldn't have considered that either. My theory was this:

The way a HUD usually works is that it positions a window directly on top of the poker table, covering it entirely. It has settings that makes it's background transparent, but the foreground not-transparent, so the foreground elements appear to float over the table. The HUD intercepts all the clicks, same as if you put like a browser window over the poker client, then you couldn't click on it there either.

Hm maybe I'm wrong and clicks on the transparent parts go through to the underlying windows. I don't remember. I wrote a HUD but it was, uh, like 12 years ago.
RustyBrooks is offline   Reply With Quote
Old 11-07-2018, 01:11 PM   #1968
matrat
adept
 
matrat's Avatar
 
Join Date: Jan 2011
Location: Valar Morghulis
Posts: 746
Re: Programming homework and newbie help thread

Help with upcasting in Java please.

Code:
class Cycle {
	public int wheels = 0;
	public int wheels() {
		return wheels;
	}
} 

class Unicycle extends Cycle {
	public int wheels = 1;
	public int wheels() {
		return wheels;
	}
}

public class Vehicles {
	public static void ride(Cycle cycle) {
		System.out.println("Number of wheels: " + cycle.wheels);
	}
	public static void main(String[] args) {
		Unicycle unicycle1 = new Unicycle();
		ride(unicycle1);
		System.out.println(unicycle1.wheels());
	}
}
ride(unicycle1) prints out 0, and println(unicycle1.wheels()) prints out 1. Why is ride() not printing out 1 as well?
matrat is offline   Reply With Quote
Old 11-07-2018, 01:16 PM   #1969
matrat
adept
 
matrat's Avatar
 
Join Date: Jan 2011
Location: Valar Morghulis
Posts: 746
Re: Programming homework and newbie help thread

As is tradition for me, as soon as I ask for help on something I figure it out.

System.out.println("Number of wheels: " + cycle.wheels); should be System.out.println("Number of wheels: " + cycle.wheels());
matrat is offline   Reply With Quote

Reply
      

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Forum Jump


All times are GMT -4. The time now is 11:26 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Copyright © 2008-2017, Two Plus Two Interactive
 
 
Poker Players - Streaming Live Online