This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's TI-BASIC subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. TI-Basic => TI-BASIC
Author Message
cssc


Newbie


Joined: 04 Jan 2008
Posts: 36

Posted: 30 May 2009 12:02:16 pm    Post subject:

Hey all, I'm trying to make a mastermind game (at my friends request) but I'm having trouble computing the amount of white pegs (a number that is right, but in the wrong space). I can find the red pegs easily, but can someone help with the white?

Here is the code i'm using to find the red and white pegs that comes closest to being right each time: L2 is the guess W is white pegs R is red pegs


Code:

DelvarRDelvarW
For(X,1,4)
W+(sum(L2=L1(X)) and sum(L1=L1(X))=sum(L2=L2(X ->W
End
R+(sum(L2=L1 ->R
W-R ->W


Thanks for any help. The problems mostly arise in the adding of white pegs already counted for due to doubles either in the target sequence or in the guess. I looked at many different pages to try to find an answer to no avail Sad
Back to top
Mapar007


Advanced Member


Joined: 04 Oct 2008
Posts: 365

Posted: 30 May 2009 01:08:03 pm    Post subject:

(assuming L1 contains the correct code)

DelvarWFor(X,1,4
If max(L1(X)=L2) and not(L1(X)=L2(X
W=W+1
End

(untested, unsure, basic is a long time ago Razz)


Last edited by Guest on 30 May 2009 01:08:52 pm; edited 1 time in total
Back to top
cssc


Newbie


Joined: 04 Jan 2008
Posts: 36

Posted: 30 May 2009 01:34:03 pm    Post subject:

It seems to work for what tests I've tried with it, thank you very much!
Back to top
darkstone knight


Advanced Member


Joined: 07 Sep 2008
Posts: 438

Posted: 30 May 2009 03:46:36 pm    Post subject:

Quote:
W=W+1


hey! this aint Java Wink
Back to top
woodswolf


Advanced Newbie


Joined: 26 Feb 2009
Posts: 53

Posted: 30 May 2009 03:52:21 pm    Post subject:

Haha, I remember coding like that when I first came in touch with a ti84+.

I was like:" Why the hell ain't this working!"
Back to top
Graphmastur


Advanced Member


Joined: 25 Mar 2009
Posts: 360

Posted: 30 May 2009 05:55:48 pm    Post subject:

darkstone knight wrote:
Quote:
W=W+1


hey! this aint Java Wink


Funny that you would assume java, and not C.

It took me a while to go from basic to java, but it was worth it. 3d engines look better in color, on a 1440 by 900 pixel screen, with millions of colors, than a 95 by 64 pixel screen, with 2 colors.

Did you understand the code that MapAr007 gave you? It can be used for many applications like that.
Back to top
TI-newb


Member


Joined: 24 Dec 2008
Posts: 158

Posted: 30 May 2009 06:29:20 pm    Post subject:

im gonna go into C++... but i really like Basic right now. so C++ can come later XD *Plus, u can't play C++ games in Class with ur calculator. Lolsssss*
Back to top
Graphmastur


Advanced Member


Joined: 25 Mar 2009
Posts: 360

Posted: 30 May 2009 07:34:27 pm    Post subject:

I would start out with an easier language like java.
Back to top
TI-newb


Member


Joined: 24 Dec 2008
Posts: 158

Posted: 30 May 2009 07:48:02 pm    Post subject:

where would i get a compiler? plz send me a link XD and i'l see if i wanna do java *u might hafta teach me unless thers some Readme.
Back to top
Graphmastur


Advanced Member


Joined: 25 Mar 2009
Posts: 360

Posted: 30 May 2009 08:05:20 pm    Post subject:

http://www.netbeans.org/

http://www.netbeans.org/kb/
Back to top
cssc


Newbie


Joined: 04 Jan 2008
Posts: 36

Posted: 31 May 2009 09:43:17 am    Post subject:

On a side note, the code doesn't seem to work :(

If the target code is {6,2,4,1}
and I input {1,2,3,4}

I should get one red peg, which I do, and two white pegs for the 1 and the 4. However the code only gives me one white peg.

Can anyone see what is wrong?
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 31 May 2009 12:25:27 pm    Post subject:

So the red pegs calculation is trivial, sum(L1=L2→R, as you've already figured out. For the white pegs, the most straightforward thing to do is this:

DelVar WFor(X,1,4
For(Y,1,4
If L1(X)=L2(Y
Then
W+1→W
0→L2(Y
End
End
End


This modifies L2, so be sure to do anything else you need to do with it (such as calculating R) first. Or make a copy.

I might think of some clever way to do it later, but this is the very simple way, and is sure to correctly compare multiple matches of the same number. Also, I'm assuming 0 is not allowed in the sequence: if it is, replace 0→L2(Y with -1→L2(Y or something like that.

Edit:

Here's a different way of doing this. This time, the loop is over all possible symbols, which I am again assuming is 1 through 9 (if it's something else, change the limits, highlighted in red):

sum(seq(min(sum(L1=X),sum(L2=X)),X,1,9
Ans-R→W


Last edited by Guest on 11 Jul 2010 03:14:54 pm; edited 1 time in total
Back to top
cssc


Newbie


Joined: 04 Jan 2008
Posts: 36

Posted: 31 May 2009 06:55:23 pm    Post subject:

Wow that worked perfectly, I understand how the first version works, but the second is a little bit beyond my comprehension haha. Thank you very much
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 31 May 2009 07:03:08 pm    Post subject:

The second version is fairly easy to understand as well, it's just in a condensed form that you might not be familiar with. The idea is that for each number, we count how many times it appears in L1, then count how many times it appears in L2 , then take the minimum of these. The result is the number of pegs that that number contributes. This is what the min(sum(X=L1),sum(X=L2)) part does.

Then we sum over all possible numbers, finding the total number of pegs. If we subtract the red pegs (which we already know how to count) we get the number of white pegs.


Last edited by Guest on 11 Jul 2010 03:14:35 pm; edited 1 time in total
Back to top
cssc


Newbie


Joined: 04 Jan 2008
Posts: 36

Posted: 01 Jun 2009 06:12:41 am    Post subject:

Oh ok, that's not bad at all. I guess I just get afraid when I see you or Weregoose use that many commands in one line ha. Thanks again
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement