board = [
['R', 'P', ' ', ' ', ' ', ' ', 'p','r'],
['N', 'P', ' ', ' ', ' ', ' ', 'p','n'],
['B', 'P', ' ', ' ', ' ', ' ', 'p','b'],
['K', 'P', ' ', ' ', ' ', ' ', 'p','k'],
['Q', 'P', ' ', ' ', ' ', ' ', 'p','q'],
['B', 'P', ' ', ' ', ' ', ' ', 'p','b'],
['N', 'P', ' ', ' ', ' ', ' ', 'p','n'],
['R', 'P', ' ', ' ', ' ', ' ', 'p','r']
]
if piece = 'k' or piece = 'K'
oking = new Model3d(oPieceEntity, oking, "models/king.obj")
oking.setModelpos(i*17-75, 0, (7-j)*17-42)
oking.setmodelSiz(0.17, 0.18, 0.17)
// oking.removeComponent()
// White piece.
if ascii(piece) < 96
oking{
SetModelTexture("textures/WhitePiece.jpg")
setModelDirection( 0, 1, 0, 90)
}
if selectionI = i and selectionJ = j
oking{
SetModelTexture("textures/WhitePieceCliked.jpg")
}
ok
// Black piece.
else
oking{
SetModelTexture("textures/Black Piece.jpg")
setModelDirection( 0, 1, 0, 270)
}
if selectionI = i and selectionJ = j
oking{
SetModelTexture("textures/BlackPieceCliked.jpg")
}
ok
ok
//---------------------Use-------------------------------
// entity = new QEntity(.......)
//DeleteEntityRecursively(entity)
//---------------------------------------------------
func DeleteComponentRecursively(Entity)
ComponentsToDelete = Entity.Components()
for Component in ComponentsToDelete
Entity.removeComponent(Component)
Del(ComponentsToDelete, Component)
Component = Nullpointer()
next
ChildrenNodes = Entity.ChildNodes()
for ChildNnode in ChildrenNodes
del(ChildrenNodes, childNode)
next
entity = nullpointer()
oForwardRenderer = oView.defaultFrameGraph()
oForwardRenderer{
setClearColor(new QColor() { setrgb(000,204,000,255) }) This works
setFrustumCullingEnabled(false) This does not work
setGamma(2.5) This does not work
}




oboard = new Model3d(oRootEntity, oboard, "models/board.obj"){
setmodelsiz(0.23, 0.2, 0.23)
setmodelpos(0, 0, 0)
SetModelDirection(0,1,0,degreeW)
SetModelTexture("textures/chessboard_wood.jpg")
SetModelDirection( 0, 1, 0, 90)
}
setModelpos(i*17-75, 0, (7-j)*17-42)
The correct equation is
for white pieces
setModelpos(i*17-75, 0, 37-(j*17-42))
for black pieces
setModelpos(i*17-75, 0,(j*17-42)-33)
There is another problem when selecting the pieces, he only sees 7 original pieces, the cloned copies cannot be retextured according to my understanding



al_load_bitmap(cFileName) ---> object (C Pointer)
al_destroy_bitmap(Object)
Number(3) : For some objects, the Ring Extension manage the memory automatically and delete the memory when the object is no longer used/available/accessible through Ring code
--
---
You received this message because you are subscribed to the Google Groups "The Ring Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ring-lang+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ring-lang/db7990d5-b2a6-457e-96d3-921f40199d9bn%40googlegroups.com.









if selectionI > 0 and selectionJ > 0
if validMove(board, selectionI, selectionJ, i, j, turn)
aTile[i][j][:oLoader].setSource(new QUrl("file:///"+currentdir()+"/textures/valid.png") )
ok
ok











Load "Chessboard.ring"
class MinimaxTree
Aiboard
TreeChildren = []
TreeChild = self
//---------------------------
func init(Chboard)
Aiboard = Chboard
//----------------------------------
func DistroyList(alist)
for item in alist
item= null
next
//----------------------------------
func IsImptyList(alist)
for item in alist
if isobject(item) != null
return false
ok
next
return true
//------------------------------
func MakeMove( move)
newTree =null
for TreeChild in TreeChildren
thisMove = TreeChild.Aiboard.getLastMove()
// if this is the move we're making, reuse the subtree
if thisMove = move
newTree = TreeChild
else
TreeChild = null
ok
next
if newTree != NULL
?newTree
Aiboard = newTree.Aiboard
TreeChildren = newTree.TreeChildren
DistroyList(newTree.TreeChildren)
newTree =null
else
Aiboard.MackeMove(move)
ok
//--------------------------------------------------
func getBestMove( isTurnAI , depth)
MakeChildren(isTurnAI)
maxAdvantage = -1000000
BestMove = new Move
for TreeChild in TreeChildren
Advantage = TreeChild.minimax(isTurnAI, !isTurnAI, depth)
if Advantage > maxAdvantage
maxAdvantage = Advantage
BestMove = TreeChild.Aiboard.getLastMove()
ok
next
return BestMove
//-------------------------------------------------------
func minimax( isTurnAI, toMove, steps)
// no more steps
if steps <= 0
return Aiboard.getAdvantage(isTurnAI)
ok
MakeChildren(toMove)
result = 0
//------ opponent to move, so minimize
if toMove ^ isTurnAI
result = 1000000
for TreeChild in TreeChildren
Advantage = TreeChild.minimax(isTurnAI, !toMove, steps - 1)
if Advantage < result result = Advantage ok
next
//------ player to move, so maximize
else
result = -1000000
for TreeChild in TreeChildren
Advantage = TreeChild.minimax(isTurnAI, !toMove, steps - 1)
if Advantage > result result = Advantage ok
next
ok
return result
//------------------------------------
func MakeChildren(isTurnAI)
? "IsImptyList :"+IsImptyList(TreeChildren)+":" +len(TreeChildren)
//---- only run if nothing has been added to list
if IsImptyList(TreeChildren)
for LegalMove in Aiboard.getLegalMove(isTurnAI)
Tree = new MinimaxTree(Aiboard)
Tree.makeMove(LegalMove)
TreeChildren + Tree
next
ok
? "len TreeChildren 2 :"+len(TreeChildren)
Hello Mahmoud
I had asked you how to send a list or attribute of an object I just developed a little function List2Code
We can now put the attributes of an object in a list
Convert it to string and then send it when it is received Execute it in memory using the eval function
//--------------------------
func ListToCode(aList)
cCode ="["
lStart = True
for item in aList
if !lStart cCode += "," +Windowsnl() else lStart = False ok
if isString(item) cCode += char(39)+ item +char(39)
but isnumber(item) cCode += ""+item
but islist(item) cCode += ListToCode(item)
but isobject(item)
aAttribut = attributes(item)
cCode += '['
lStart = True
for attribut in aAttribut
if !lStart cCode += "," else lStart = False ok
value = getattribute(item,attribut)
cCode +=':'+ attribut + '='
if isString(value)
cCode += '"' + value + '"'
but isNumber(value)
cCode += value
but isList(value)
cCode += ListToCode(value)
but isobject(value)
cCode += ListToCode(value)
ok
next
cCode += " ]"
ok
next
cCode += "]"+Windowsnl()
return cCode
//-------------------------
func writeMessage(cStr)
Message ="aCommand="
Message += cStr
if networkMode
oClient.sendMessage(Message)
else
oServer.sendMessage(Message)
ok
Hello Mahmoud
alist = "a" : "z"
alist2 = 0 : 1
alist3 = [4 ,8 , "a" , "z" ,"A" , "Z",10 , 100]
? RandomList(alist)
? RandomList(alist2)
? RandomList(alist3)
//------------------------------------
func RandomList(aInput)
alist = aInput
aOutput = null
while len(alist) > 1
nIndex = random(len(alist)-1)
nIndex++
aOutput = alist[nIndex]
del(alist,nIndex)
end
return aOutput
RE: --- We can install it using the Ring Package Manager
