Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Readers > Amazon Kindle > Kindle Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 07-14-2012, 06:59 AM   #1
mmatej
Connoisseur
mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.
 
Posts: 91
Karma: 14730
Join Date: Jun 2012
Device: none
Puzzle swapping minigame

I was so bored that I've made this stupid minigame. It's written as shell script, so don't expect it wil be fast as hell. (init takes 3 mins)
Spoiler:

Code:
#!/bin/sh
[ "${#}" -ne 2 ] &&
{
echo "Usage: ${0} <blocks per X> <blocks per Y>"
return 1
}
fb='/dev/fb0'
ddfb()# <bs> <count> [skip] [seek]
{
sk=0
se=0
[ -n "${3}" ] && sk="${3}"
[ -n "${4}" ] && se="${4}"
dd if="${fb}" of="${fb}" bs=${1} count=${2} skip=${sk} seek=${se} > /dev/null 2>&1
}
copyH()# <fromY> <toY> <height>
{
ddfb 608 "${3}" "${1}" "${2}"
}
copyrect()# <fromX> <fromY> <width> <height> <toX> <toY>
{
fendY=$(expr ${2} + ${4})
taY=${6}
for i in $(seq ${2} ${fendY}); do
ddfb 1 ${3} $(expr 608 \* ${i} + ${1}) $(expr 608 \* ${taY} + ${5})
taY=$(expr ${taY} + 1)
done
}
fillrect()# <toX> <toY> <width> <height> [hex_color]
{
hex='00'
[ -n "${5}" ] &&
{
hex=${5}
[ "${#hex}" -ne 2 ] && hex='0'"${hex}"
}
fendY=$(expr ${2} + ${4})
taY=${2}
for i in $(seq ${2} ${fendY}); do
[ "${hex}" == '00' ] && dd if="/dev/zero" of="${fb}" bs=1 count=${3} seek=$(expr ${i} \* 608 + ${1}) > /dev/null 2>&1
[ "${hex}" != '00' ] && cat /dev/zero|tr '\x00' '\x'"${hex}"|dd of="${fb}" bs=1 count=${3} seek=$(expr ${i} \* 608 + ${1}) > /dev/null 2>&1
taY=$(expr ${taY} + 1)
done
}
grid()
{
for x in $(seq 1 "$(expr ${X} - 1)"); do fillrect $(expr ${x} \* ${W} - ${T}) 0 $(expr 2 \* ${T}) 800; done
for y in $(seq 1 "$(expr ${Y} - 1)"); do fillrect 0 $(expr ${y} \* ${H} - ${T}) 600 $(expr 2 \* ${T}); done
fillrect 0 0 600 1
fillrect 0 800 600 1
fillrect 0 0 1 800
fillrect 600 0 1 800
}
blitblock()
{
fr="$(expr ${2} + ${NUM} - 1)"
to="$(expr ${1} - 1)"
fx=$(expr "$(expr ${fr} % ${X})" \* ${W})
fy=$(expr "$(expr ${fr} / ${X})" \* ${H})
tx=$(expr "$(expr ${to} % ${X})" \* ${W})
ty=$(expr "$(expr ${to} / ${X})" \* ${H})
copyrect ${fx} ${fy} ${W} ${H} ${tx} ${ty}
}
blitchanged()
{
[ "${oblocks}" == "${blocks}" ] && return
echo -n "Updating changed blocks... "
for i in $(seq 1 ${NUM}); do
old="$(getf "$oblocks" ${i})"
new="$(getf "$blocks" ${i})"
if [ "${old}" != "${new}" ]; then
blitblock ${i} ${new}
fi
done
oblocks="${blocks}"
echo 'done'
}
swap()
{
to1="$(getf "${blocks}" ${1})"
to2="$(getf "${blocks}" ${2})"
nblocks=''
for i in $(seq 1 ${NUM}); do
[ ${i} -ne 1 ] && nblocks="${nblocks}"' '
[ ${i} -eq ${1} ] &&
{
nblocks="${nblocks}""${to2}"
continue
}
[ ${i} -eq ${2} ] &&
{
nblocks="${nblocks}""${to1}"
continue
}
a="$(getf "${blocks}" ${i})"
nblocks="${nblocks}""${a}"
done
blocks="${nblocks}"
}
decode16()
{
local b="$(echo "$1"|cut -d' ' -f 1)"
local a="$(echo "$1"|cut -d' ' -f 2)"
echo "$(expr 256 \* $a + $b)"
}
randnum()
{
rstr="$(xd -qdbl 3 /dev/urandom|cut -d' ' -f 2,3,4)"
c="$(getf "${rstr}" 1)"
b="$(getf "${rstr}" 2)"
a="$(getf "${rstr}" 3)"
rnum="$(expr 65536 \* ${a} + 256 \* ${b} + ${c})"
echo "$(expr ${rnum} % "$(expr ${2} - ${1} + 1)" + ${1})"
}
getf()
{
echo "$(echo "${1}"|cut -d' ' -f ${2})"
}
getdiff()
{
first=${1}
second=${2}
[ ${2} -gt ${1} ] &&
{
first=${2}
second=${1}
}
echo "$(expr ${first} - ${second})"
}
checkgame()
{
local count=0
for i in $(seq 1 ${NUM}); do
local acb="$(getf "${blocks}" ${i})"
[ ${acb} -ne ${i} ] && count="$(expr ${count} + 1)"
done
echo "${count}"
}

[ "$(expr 608 % ${1})" -ne 0 ] && { echo "608 not divisable by ${1} (X)";return 1; }
[ "$(expr 800 % ${2})" -ne 0 ] && { echo "800 not divisable by ${2} (Y)";return 1; }
killall -stop cvm framework Xorg
trap "copyH 1600 0 800;eips -f '';killall -cont cvm framework Xorg;exit;" SIGINT SIGTERM EXIT
echo "Initializing..."
X=${1}
Y=${2}
W="$(expr 600 / ${X})"
H="$(expr 800 / ${Y})"
NUM="$(expr ${X} \* ${Y})"
T=1
IFS='
'
blocks=''
for i in $(seq 1 ${NUM}); do
[ ${i} -ne 1 ] && blocks="${blocks}"' '
blocks="${blocks}""${i}"
done
oblocks="${blocks}"
copyH 0 1600 800
echo "Creating grid..."
grid
copyH 0 800 800
eips ''
echo "Shuffling blocks..."
rseq=''
for i in $(seq 1 ${NUM}); do
[ ${i} -ne 1 ] && rseq="${rseq}"' '
rseq="${rseq}""${i}"
done
blocks=''
for i in $(seq 1 ${NUM}); do
echo "${i}/${NUM}"
to="$(expr ${NUM} - ${i} + 1)"
rn="$(randnum 1 "${to}")"
nseq=''
added=0
for j in $(seq 1 "${to}"); do
tnum="$(getf "${rseq}" ${j})"
[ ${j} -eq ${rn} ] &&
{
[ ${i} -ne 1 ] && blocks="${blocks}"' '
blocks="${blocks}""${tnum}"
continue
}
[ ${added} -eq 1 ] && nseq="${nseq}"' '
nseq="${nseq}""${tnum}"
added=1
done
rseq="${nseq}"
done
#blocks="${oblocks}"
blitchanged
echo "Done."
eips -f ''

sel=0
oldx=0
oldy=0
while true; do
bb=-1
[ ${sel} -eq 0 ] && bb="$(checkgame)"
[ ${bb} -eq 0 ] &&
{
trap - SIGINT SIGTERM EXIT
trap "eips -f '';killall -cont cvm framework Xorg;exit;" SIGINT SIGTERM EXIT
copyH 1600 0 800
eips ''
echo "You have won!"
sleep 5
break
}
[ ${bb} -ne -1 ] && echo "You have ${bb} misplaced blocks."
have_e=0
xa=0
ya=0
while [ ${have_e} -eq 0 ]; do
for data in $(xd -qdbl 96 /dev/input/event3); do
[ "$(getf "${data}" 10)" -ne '003' ] && continue
code="$(getf "${data}" 12)"
[ "${code}" == '057' ] && continue
pos="$(echo "${data}"|cut -d' ' -f 14,15)"
rpos="$(decode16 "${pos}")"
[ ${code} -eq 53 ] && xa="${rpos}"
[ ${code} -eq 54 ] && ya="${rpos}"
done
have_e=1
[ ${xa} -eq 0 ] && { have_e=0;continue; }
[ ${ya} -eq 0 ] && { have_e=0;continue; }
break
done
xr="$(expr ${xa} \* 600 / 4095)"
yr="$(expr ${ya} \* 800 / 4095)"
x="$(expr ${xr} / ${W})"
y="$(expr ${yr} / ${H})"
bid="$(expr ${y} \* ${X} + ${x} + 1)"
[ ${sel} -eq 0 ] &&
{
sel="${bid}"
echo -n "${sel} -> "
oldx=${x}
oldy=${y}
continue
}
[ ${bid} -eq ${sel} ] &&
{
echo 'X'
sel=0
continue
}
xchange="$(getdiff ${oldx} ${x})"
ychange="$(getdiff ${oldy} ${y})"
poschange="$(expr ${xchange} + ${ychange})"
[ ${poschange} -ne 1 ] &&
{
echo 'X'
sel=0
continue
}
echo "${bid}"
swap ${sel} ${bid}
blitchanged
eips ''
sel=0
done
dd if="/dev/zero" of="/dev/fb0" bs=608 seek=800 > /dev/null 2>&1
exit

Screen:
Spoiler:

You can swap only adjacent blocks. Have fun!
mmatej is offline   Reply With Quote
Old 07-14-2012, 07:25 AM   #2
twobob
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Týr
twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.
 
twobob's Avatar
 
Posts: 6,586
Karma: 6299991
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
Quality. Everyone in my house - by sheer coincidence - is terrible at these puzzles.

MUHAHHAHHAHA! I can definitely see this being installed and run while some is at the bathroom

have to see about a c port of this. Great work mate
twobob is offline   Reply With Quote
Advert
Old 07-14-2012, 07:29 AM   #3
aditya3098
Guru
aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.
 
Posts: 608
Karma: 1588610
Join Date: Jan 2012
Device: Kindle Scribe
Initiating...
aditya3098 is offline   Reply With Quote
Old 07-14-2012, 07:40 AM   #4
mmatej
Connoisseur
mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.
 
Posts: 91
Karma: 14730
Join Date: Jun 2012
Device: none
Quote:
Originally Posted by twobob View Post
Quality. Everyone in my house - by sheer coincidence - is terrible at these puzzles.

MUHAHHAHHAHA! I can definitely see this being installed and run while some is at the bathroom

have to see about a c port of this. Great work mate
Good and evil use of the game
I've firstly wanted to write this in C++, but I wasn't able to cross-compile hello world for KT on Ubuntu. I know about tcc for the Kindle, but I hate C (C-like languages are ugly without things like STL which speeds up development process a lot).
mmatej is offline   Reply With Quote
Old 07-14-2012, 07:42 AM   #5
mmatej
Connoisseur
mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.
 
Posts: 91
Karma: 14730
Join Date: Jun 2012
Device: none
Quote:
Originally Posted by aditya3098 View Post
Initiating...
It should not take more than 5 mins. (sure if you set 100x200 grid it will take years). Is it still initializing?
mmatej is offline   Reply With Quote
Advert
Old 07-14-2012, 07:44 AM   #6
aditya3098
Guru
aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.
 
Posts: 608
Karma: 1588610
Join Date: Jan 2012
Device: Kindle Scribe
Yes, and I set 304x400
aditya3098 is offline   Reply With Quote
Old 07-14-2012, 07:48 AM   #7
aditya3098
Guru
aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.
 
Posts: 608
Karma: 1588610
Join Date: Jan 2012
Device: Kindle Scribe
The wiki is slightly mistaken (will update it in a few minutes)
install using sudo apt-get install gcc-4.6-arm-linux-gnueabi


And execute using arm-linux-gnueabi-gcc-4.6. (i.e arm-linux-gnueabi-gcc-4.6 hello.c -o hello)
aditya3098 is offline   Reply With Quote
Old 07-14-2012, 08:00 AM   #8
mmatej
Connoisseur
mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.
 
Posts: 91
Karma: 14730
Join Date: Jun 2012
Device: none
Quote:
Originally Posted by aditya3098 View Post
The wiki is slightly mistaken (will update it in a few minutes)
install using sudo apt-get install gcc-4.6-arm-linux-gnueabi


And execute using arm-linux-gnueabi-gcc-4.6. (i.e arm-linux-gnueabi-gcc-4.6 hello.c -o hello)
Thanks, but I didn't say I've failed at the "install build toolset" part. I was able to install build env. I was able to compile program which returns 0 (there were no headers included). I was not able to compile when I've included iostream and used it - there were some weird header errors which I've seen the first time. I have no cross-compiling experience, so I think it's only minor problem, but I haven't had time to investigate further.
mmatej is offline   Reply With Quote
Old 07-14-2012, 08:00 AM   #9
geekmaster
Carpe diem, c'est la vie.
geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.
 
geekmaster's Avatar
 
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
Nice to see something new coming out of my work on the eink algorithmic art scripting thread. Using "dd" as a blitter to draw on the framebuffer device is classic.

Other people have contributed scripts to the "algorithmic art" thread too, and PoP even converted his "3D" script to a C program later.

Doing this stuff in a script is more just for fun, to show that it CAN be done even with the most primitive of tools. That alone makes it really cool!

Thanks for sharing.
geekmaster is offline   Reply With Quote
Old 07-14-2012, 08:15 AM   #10
mmatej
Connoisseur
mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.
 
Posts: 91
Karma: 14730
Join Date: Jun 2012
Device: none
Quote:
Originally Posted by aditya3098 View Post
Yes, and I set 304x400
EDIT: Did you want to set 2x2 grid? You should run it with "./puzzle.sh 2 2" then.

Last edited by mmatej; 07-14-2012 at 08:27 AM.
mmatej is offline   Reply With Quote
Old 07-14-2012, 08:26 AM   #11
aditya3098
Guru
aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.aditya3098 ought to be getting tired of karma fortunes by now.
 
Posts: 608
Karma: 1588610
Join Date: Jan 2012
Device: Kindle Scribe
Still loading, and hourly indian power cuts don't help. Get about 12 hour of power daily.
aditya3098 is offline   Reply With Quote
Old 07-14-2012, 08:39 AM   #12
mmatej
Connoisseur
mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.mmatej is less competitive than you.
 
Posts: 91
Karma: 14730
Join Date: Jun 2012
Device: none
Quote:
Originally Posted by aditya3098 View Post
Still loading, and hourly indian power cuts don't help. Get about 12 hour of power daily.
See my previous post. I am testing now 16x32 grid and it looks unplayable.
EDIT: Yes, it's pure masochism:
Spoiler:
(mobileread website)

Last edited by mmatej; 07-14-2012 at 08:58 AM.
mmatej is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Greetings! Swapping Nook for Simple Touch pdxreads Introduce Yourself 4 07-02-2011 02:50 PM
Classic Swapping out the internal SD card apastuszak Barnes & Noble NOOK 1 06-22-2011 04:10 PM
Swapping title/author The Big Kahuna Calibre 6 06-08-2011 10:58 PM
Swapping memory cards emonti8384 Sony Reader 9 07-04-2009 02:04 AM
P-Book Swapping Sites? Gatton Lounge 6 06-25-2007 12:10 AM


All times are GMT -4. The time now is 08:54 PM.


MobileRead.com is a privately owned, operated and funded community.