BaseX query optimization on join - query-optimization

After the issue in the following Stackoverflow is fixed, I have another problem when I try to make a join as below. The last query takes about 250ms while the first two take only 16ms. Is there a better way to perform join between two items?
Note: You can find the test data from this link.
let $PlGeTys :=
/root/PlGeTys/PlGeTy[
isOfPlCt/#href=/root/PlCts/PlCt[
environment='AIR'
]/#id
]
let $PlSpTys :=
/root/PlSpTys/PlSpTy[
isOfPlGeTy/#href=$PlGeTys/#id
]
for $PlGeTy in $PlGeTys,
$PlSpTy in $PlSpTys
where $PlSpTy/isOfPlGeTy/#href=$PlGeTy/#id
return <done>{$PlGeTy, $PlSpTy }</done>
Here is the query info:
Compiling:
- applying attribute index for $PlGeTys_0/#*:id
- rewriting where clause(s)
Query:
let $PlGeTys := /root/PlGeTys/PlGeTy[ isOfPlCt/#href=/root/PlCts/PlCt[ environment='AIR' ]/#id ] let $PlSpTys := /root/PlSpTys/PlSpTy[ isOfPlGeTy/#href=$PlGeTys/#id ] for $PlGeTy in $PlGeTys, $PlSpTy in $PlSpTys where $PlSpTy/isOfPlGeTy/#href=$PlGeTy/#id return "done"
Optimized Query:
let $PlGeTys_0 := db:open-pre("Output6",0)/*:root/*:PlGeTys/*:PlGeTy[(*:isOfPlCt/#*:href = root()/*:root/*:PlCts/*:PlCt[(*:environment = "AIR")]/#*:id)] let $PlSpTys_1 := db:attribute("Output6", $PlGeTys_0/#*:id)/self::*:href/parent::*:isOfPlGeTy/parent::*:PlSpTy for $PlGeTy_2 in $PlGeTys_0 for $PlSpTy_3 in ($PlSpTys_1)[(isOfPlGeTy/#href = $PlGeTy_2/#*:id)] return "done"
Result:
- Hit(s): 3642 Items
- Updated: 0 Items
- Printed: 18209 Bytes
- Read Locking: local [Output6]
- Write Locking: none
Timing:
- Parsing: 0.77 ms
- Compiling: 0.47 ms
- Evaluating: 215.71 ms
- Printing: 0.17 ms
- Total Time: 217.11 ms
Query plan:
<QueryPlan compiled="true">
<GFLWOR>
<Let>
<Var name="$PlGeTys" id="0"/>
<IterPath>
<DBNode name="Output6" pre="0"/>
<IterStep axis="child" test="*:root"/>
<IterStep axis="child" test="*:PlGeTys"/>
<IterStep axis="child" test="*:PlGeTy">
<CmpG op="=">
<CachedPath>
<IterStep axis="child" test="*:isOfPlCt"/>
<IterStep axis="attribute" test="*:href"/>
</CachedPath>
<IterPath>
<Root/>
<IterStep axis="child" test="*:root"/>
<IterStep axis="child" test="*:PlCts"/>
<IterStep axis="child" test="*:PlCt">
<CmpG op="=">
<CachedPath>
<IterStep axis="child" test="*:environment"/>
</CachedPath>
<Str value="AIR" type="xs:string"/>
</CmpG>
</IterStep>
<IterStep axis="attribute" test="*:id"/>
</IterPath>
</CmpG>
</IterStep>
</IterPath>
</Let>
<Let>
<Var name="$PlSpTys" id="1"/>
<CachedPath>
<ValueAccess data="Output6" type="ATTRIBUTE">
<CachedPath>
<VarRef>
<Var name="$PlGeTys" id="0"/>
</VarRef>
<IterStep axis="attribute" test="*:id"/>
</CachedPath>
</ValueAccess>
<IterStep axis="self" test="*:href"/>
<IterStep axis="parent" test="*:isOfPlGeTy"/>
<IterStep axis="parent" test="*:PlSpTy"/>
</CachedPath>
</Let>
<For>
<Var name="$PlGeTy" id="2"/>
<VarRef>
<Var name="$PlGeTys" id="0"/>
</VarRef>
</For>
<For>
<Var name="$PlSpTy" id="3"/>
<IterFilter>
<VarRef>
<Var name="$PlSpTys" id="1"/>
</VarRef>
<CmpG op="=">
<CachedPath>
<IterStep axis="child" test="isOfPlGeTy"/>
<IterStep axis="attribute" test="href"/>
</CachedPath>
<IterPath>
<VarRef>
<Var name="$PlGeTy" id="2"/>
</VarRef>
<IterStep axis="attribute" test="*:id"/>
</IterPath>
</CmpG>
</IterFilter>
</For>
<Str value="done" type="xs:string"/>
</GFLWOR>
</QueryPlan>
Update two:
The issue above is fixed. But when I want to use it in a local function as below, it takes about 700 ms. Am I doing something wrong?
declare function local:result($root as element(root)) as element()* {
let $PlCts := $root/PlCts/PlCt[environment = 'AIR']/#id
for $PlGeTy in $root/PlGeTys/PlGeTy[isOfPlCt/#href = $PlCts],
$PlSpTy in $root/PlSpTys/PlSpTy[isOfPlGeTy/#href = $PlGeTy/#id]
return <done>{ $PlGeTy, $PlSpTy }</done>
};
let $result := local:result(/root)
return $result
Query info;
Compiling:
- removing redundant element()* cast.
- inlining local:result#1
- inlining $root_5 as element(root)
- simplifying flwor expression
Query:
declare function local:result($root as element(root)) as element()* { let $PlCts := $root/PlCts/PlCt[environment = 'AIR']/#id for $PlGeTy in $root/PlGeTys/PlGeTy[isOfPlCt/#href = $PlCts], $PlSpTy in $root/PlSpTys/PlSpTy[isOfPlGeTy/#href = $PlGeTy/#id] return <done>{ $PlGeTy, $PlSpTy }</done> }; let $result := local:result(/root) return $result
Optimized Query:
let $PlCts_6 := ((: element(root), true :) db:open-pre("Output6",0)/*:root)/PlCts/PlCt[(environment = "AIR")]/#id let $result_4 := for $PlGeTy_7 in ((: element(root), true :) db:open-pre("Output6",0)/*:root)/PlGeTys/PlGeTy[(isOfPlCt/#href = $PlCts_6)] for $PlSpTy_8 in ((: element(root), true :) db:open-pre("Output6",0)/*:root)/PlSpTys/PlSpTy[(isOfPlGeTy/#href = $PlGeTy_7/#id)] return element done { (($PlGeTy_7, $PlSpTy_8)) } return $result_4
Result:
- Hit(s): 3642 Items
- Updated: 0 Items
- Printed: 553 KB
- Read Locking: local [Output6]
- Write Locking: none
Timing:
- Parsing: 1.41 ms
- Compiling: 2.9 ms
- Evaluating: 581.5 ms
- Printing: 8.34 ms
- Total Time: 594.15 ms
Query plan:
<QueryPlan compiled="true">
<GFLWOR>
<Let>
<Var name="$PlCts" id="6"/>
<IterPath>
<TypeCheck type="element(root)" function="true">
<IterPath>
<DBNode name="Output6" pre="0"/>
<IterStep axis="child" test="*:root"/>
</IterPath>
</TypeCheck>
<IterStep axis="child" test="PlCts"/>
<IterStep axis="child" test="PlCt">
<CmpG op="=">
<CachedPath>
<IterStep axis="child" test="environment"/>
</CachedPath>
<Str value="AIR" type="xs:string"/>
</CmpG>
</IterStep>
<IterStep axis="attribute" test="id"/>
</IterPath>
</Let>
<Let>
<Var name="$result" id="4"/>
<GFLWOR>
<For>
<Var name="$PlGeTy" id="7"/>
<IterPath>
<TypeCheck type="element(root)" function="true">
<IterPath>
<DBNode name="Output6" pre="0"/>
<IterStep axis="child" test="*:root"/>
</IterPath>
</TypeCheck>
<IterStep axis="child" test="PlGeTys"/>
<IterStep axis="child" test="PlGeTy">
<CmpG op="=">
<CachedPath>
<IterStep axis="child" test="isOfPlCt"/>
<IterStep axis="attribute" test="href"/>
</CachedPath>
<VarRef>
<Var name="$PlCts" id="6"/>
</VarRef>
</CmpG>
</IterStep>
</IterPath>
</For>
<For>
<Var name="$PlSpTy" id="8"/>
<IterPath>
<TypeCheck type="element(root)" function="true">
<IterPath>
<DBNode name="Output6" pre="0"/>
<IterStep axis="child" test="*:root"/>
</IterPath>
</TypeCheck>
<IterStep axis="child" test="PlSpTys"/>
<IterStep axis="child" test="PlSpTy">
<CmpG op="=">
<CachedPath>
<IterStep axis="child" test="isOfPlGeTy"/>
<IterStep axis="attribute" test="href"/>
</CachedPath>
<IterPath>
<VarRef>
<Var name="$PlGeTy" id="7"/>
</VarRef>
<IterStep axis="attribute" test="id"/>
</IterPath>
</CmpG>
</IterStep>
</IterPath>
</For>
<CElem>
<QNm value="done" type="xs:QName"/>
<List>
<VarRef>
<Var name="$PlGeTy" id="7"/>
</VarRef>
<VarRef>
<Var name="$PlSpTy" id="8"/>
</VarRef>
</List>
</CElem>
</GFLWOR>
</Let>
<VarRef>
<Var name="$result" id="4"/>
</VarRef>
</GFLWOR>
</QueryPlan>
Update three:
Now, I have another issue when I extend the query with the additional "Cont" items, The query execution lasts about 600 ms. But without "Cont" items, it takes only 35 ms.
Do you any suggestion on optimizing this query?
let $PlCts := /root/PlCts/PlCt[environment = 'AIR']/#id
for $PlGeTy in /root/PlGeTys/PlGeTy[isOfPlCt/#href = $PlCts],
$PlSpTy in /root/PlSpTys/PlSpTy[isOfPlGeTy/#href = $PlGeTy/#id],
$Cont in /root/Conts/Cont[#id=$PlSpTy/isOfCont/#href]
return <done>{ $PlGeTy, $PlSpTy, $Cont }</done>
This is the link of the latest XML data for testing.
The query info:
Compiling:
- applying text index for "AIR"
- applying attribute index for $PlCts_0
- applying attribute index for $PlGeTy_1/#id
- applying attribute index for $PlSpTy_2/isOfCont/#href
- inlining $PlCts_0
Query:
let $PlCts := /root/PlCts/PlCt[environment = 'AIR']/#id for $PlGeTy in /root/PlGeTys/PlGeTy[isOfPlCt/#href = $PlCts], $PlSpTy in /root/PlSpTys/PlSpTy[isOfPlGeTy/#href = $PlGeTy/#id], $Cont in /root/Conts/Cont[#id=$PlSpTy/isOfCont/#href] return <done>{ $PlGeTy, $PlSpTy, $Cont }</done>
Optimized Query:
for $PlGeTy_1 in db:attribute("Output7", db:text("Output7", "AIR")/parent::*:environment/parent::*:PlCt/#*:id)/self::*:href/parent::*:isOfPlCt/parent::*:PlGeTy for $PlSpTy_2 in db:attribute("Output7", $PlGeTy_1/#id)/self::*:href/parent::*:isOfPlGeTy/parent::*:PlSpTy for $Cont_3 in db:attribute("Output7", $PlSpTy_2/isOfCont/#href)/self::*:id/parent::*:Cont return element done { (($PlGeTy_1, $PlSpTy_2, $Cont_3)) }
Result:
- Hit(s): 3642 Items
- Updated: 0 Items
- Printed: 1159 KB
- Read Locking: local [Output7]
- Write Locking: none
Timing:
- Parsing: 0.39 ms
- Compiling: 0.68 ms
- Evaluating: 585.29 ms
- Printing: 14.36 ms
- Total Time: 600.72 ms
Query plan:
<QueryPlan compiled="true">
<GFLWOR>
<For>
<Var name="$PlGeTy" id="1"/>
<CachedPath>
<ValueAccess data="Output7" type="ATTRIBUTE">
<CachedPath>
<ValueAccess data="Output7" type="TEXT" name="*:environment">
<Str value="AIR" type="xs:string"/>
</ValueAccess>
<IterStep axis="parent" test="*:PlCt"/>
<IterStep axis="attribute" test="*:id"/>
</CachedPath>
</ValueAccess>
<IterStep axis="self" test="*:href"/>
<IterStep axis="parent" test="*:isOfPlCt"/>
<IterStep axis="parent" test="*:PlGeTy"/>
</CachedPath>
</For>
<For>
<Var name="$PlSpTy" id="2"/>
<CachedPath>
<ValueAccess data="Output7" type="ATTRIBUTE">
<IterPath>
<VarRef>
<Var name="$PlGeTy" id="1"/>
</VarRef>
<IterStep axis="attribute" test="id"/>
</IterPath>
</ValueAccess>
<IterStep axis="self" test="*:href"/>
<IterStep axis="parent" test="*:isOfPlGeTy"/>
<IterStep axis="parent" test="*:PlSpTy"/>
</CachedPath>
</For>
<For>
<Var name="$Cont" id="3"/>
<CachedPath>
<ValueAccess data="Output7" type="ATTRIBUTE">
<IterPath>
<VarRef>
<Var name="$PlSpTy" id="2"/>
</VarRef>
<IterStep axis="child" test="isOfCont"/>
<IterStep axis="attribute" test="href"/>
</IterPath>
</ValueAccess>
<IterStep axis="self" test="*:id"/>
<IterStep axis="parent" test="*:Cont"/>
</CachedPath>
</For>
<CElem>
<QNm value="done" type="xs:QName"/>
<List>
<VarRef>
<Var name="$PlGeTy" id="1"/>
</VarRef>
<VarRef>
<Var name="$PlSpTy" id="2"/>
</VarRef>
<VarRef>
<Var name="$Cont" id="3"/>
</VarRef>
</List>
</CElem>
</GFLWOR>
</QueryPlan>

In those for loops, the results of the two "large" XPath expressions are already cached by the optimizer. Furthermore, you're actually comparing the href/id attributes twice.
Cleaning up the query removing this double effort reduces the execution time by about 90%.
let $PlCts := /root/PlCts/PlCt[environment = 'AIR']/#id
for $PlGeTy in /root/PlGeTys/PlGeTy[isOfPlCt/#href = $PlCts],
$PlSpTy in /root/PlSpTys/PlSpTy[isOfPlGeTy/#href = $PlGeTy/#id]
return <done>{ $PlGeTy, $PlSpTy }</done>

Related

Implementing #check_honeypot on Django Wagtail Form

I am trying to implement Honeypot into a Wagtail email form, but I don't understand how to add the #check_honeypot decorator to a class in models.py, which checks the honeypotfor validity.
To set up Honeypot, it requires that I add the #check_honeypot decorator to the form view in my views.py. Unfortunately, wagtail does not utilize views.py and instead the form is built in the models.py.
How to I implement honeypot decorator onto a Wagtail form?
Honeypot repo: https://github.com/jamesturk/django-honeypot
Snippet from honeypot instructions:
To ensure that the honeypot field is both present and correct you will >need to use check_honeypot decorator from honeypot.decorators:
from honeypot.decorators import check_honeypot
#check_honeypot(field_name='hp_field_name')
def post_comment(request):
...
#check_honeypot
def other_post_view(request):
...
SOLUTION:
#method_decorator(check_honeypot)
def render_landing_page
models.py
class FormField(AbstractFormField):
page = ParentalKey('FormPage', on_delete=models.CASCADE, related_name='form_fields')
class FormPage(AbstractEmailForm):
header = RichTextField(blank=True)
body = RichTextField(blank=True)
header_two = RichTextField(blank=True)
body_two = RichTextField(blank=True)
header_three = RichTextField(blank=True)
body_three = RichTextField(blank=True)
address = RichTextField(blank=True)
form_header = models.CharField(blank=True, max_length=100)
thank_you_text = RichTextField(blank=True)
content_panels = AbstractEmailForm.content_panels + [
FieldPanel('header', classname="full"),
FieldPanel('body', classname='full'),
FieldPanel('header_two', classname="full"),
FieldPanel('body_two', classname='full'),
FieldPanel('header_three', classname="full"),
FieldPanel('body_three', classname='full'),
FieldPanel('address', classname='full'),
FieldPanel('form_header', classname='full'),
InlinePanel('form_fields', label="Form fields"),
FieldPanel('thank_you_text', classname="full"),
MultiFieldPanel([
FieldRowPanel([
FieldPanel('from_address', classname="col6"),
FieldPanel('to_address', classname="col6"),
]),
FieldPanel('subject'),
], "Email"),
]
thank_you_page = models.ForeignKey(
'wagtailcore.Page',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+',
)
def render_landing_page(self, request, form_submission=None, *args, **kwargs):
if self.thank_you_page:
url = self.thank_you_page.url
# if a form_submission instance is available, append the id to URL
# when previewing landing page, there will not be a form_submission instance
if form_submission:
url += '?id=%s' % form_submission.id
return redirect(url, permanent=False)
# if no thank_you_page is set, render default landing page
return super().render_landing_page(request, form_submission, *args, **kwargs)
content_panels = AbstractEmailForm.content_panels + [
FieldPanel('header', classname="full"),
FieldPanel('body', classname='full'),
FieldPanel('header_two', classname="full"),
FieldPanel('body_two', classname='full'),
FieldPanel('header_three', classname="full"),
FieldPanel('body_three', classname='full'),
FieldPanel('address', classname='full'),
FieldPanel('form_header', classname='full'),
InlinePanel('form_fields'),
FieldPanel('thank_you_text', classname='full'),
PageChooserPanel('thank_you_page'),
MultiFieldPanel([
FieldRowPanel([
FieldPanel('from_address', classname='col6'),
FieldPanel('to_address', classname='col6'),
]),
FieldPanel('subject'),
], 'Email'),
]
form.html
<section class="contact-background-lg" >
<div class="container px-0">
<div class="card p-m-5-0">
<form action="{% pageurl page %}" method="POST">
{% csrf_token %}
{% render_honeypot_field "phonenumber" %}
<div class="row">
<div class="col-md-12 col-sm-12">
{% if form.non_field_errors %}
<div class="alert alert-danger" role="alert">
{% for error in form.non_field_errors %}
{{ error }}
{% endfor %}
</div>
{% endif %}
<div class="card-title text-primary">
<h2><strong>{{ page.form_header }}</strong></h2><p class="pb-2 text-muted">Please complete the form below to receive a response within 24 hours.</p>
<hr>
<br>
</div>
</div>
{% for field in form.visible_fields %}
<div class="col-md-6 col-sm-12">
<div class="form-group pt-3">
{{ field.label_tag }}
{% render_field field class+="form-control" %}
</div>
</div>
{% endfor %}
</div>
<div class="pull-center">
<button type="submit" class="btn btn-primary-alt py-3 mt-3" style="width: 8rem;">Submit</button>
</div>
</form>
</div>
</div>
</section>

md-autocomplete with bootstrap's class="modal-content" not working

My Main Modal Component is:-
<div class="modal-content">
<div class="modal-header"> </div>
<div class="modal-body">
<display-states-component rolesdata="$ctrl.modaldata.displayStatesRoles"></display-states-component>
</div>
</div>
DisplayStatesComponent is(Angular 1.5 Component architecture)
<form ng-submit="$event.preventDefault()">
<md-autocomplete md-no-cache="true" md-selected-item="$ctrl.displayPerRoles[$index].roleName" md-search-text="$ctrl.searchText" md-items="item in $ctrl.querySearch($ctrl.searchText)" md-item-text="item.value" md-min-length="0" placeholder="Select Role?">
<md-item-template>
<span md-highlight-text="$ctrl.searchText" md-highlight-flags="^i">{{item.value}}</span>{{item.value}}
</md-item-template>
<md-not-found>
No role matching "{{$ctrl.searchText}}" were found.
<a ng-click="$ctrl.manageStates('ADD')">Create a new one!</a>
</md-not-found>
</md-autocomplete>
</form>
And MY Corresponding Display States Controller is:-
$ctrl.states = loadAll();
$ctrl.querySearch = function(query) {
var results = query ? $ctrl.states.filter(createFilterFor(query)) : $ctrl.states,
deferred;
console.log("With my Testings in else--->", results);
return results;
}
/**
* Build `states` list of key/value pairs
*/
function loadAll() {
var allStates = 'Alabama, Alaska, Arizona, Arkansas, California, Colorado, Connecticut, Delaware,\
Florida, Georgia, Hawaii, Idaho, Illinois, Indiana, Iowa, Kansas, Kentucky, Louisiana,\
Maine, Maryland, Massachusetts, Michigan, Minnesota, Mississippi, Missouri, Montana,\
Nebraska, Nevada, New Hampshire, New Jersey, New Mexico, New York, North Carolina,\
North Dakota, Ohio, Oklahoma, Oregon, Pennsylvania, Rhode Island, South Carolina,\
South Dakota, Tennessee, Texas, Utah, Vermont, Virginia, Washington, West Virginia,\
Wisconsin, Wyoming';
return allStates.split(/, +/g).map(function(state) {
return {
value: state.toLowerCase(),
display: state
};
});
}
My Filter Functions are
function createFilterFor(query) {
var lowercaseQuery = angular.lowercase(query);
return function filterFn(state) {
return (state.value.indexOf(lowercaseQuery) === 0);
}
};
I am using this code to search for states as the user types state name in autocomplete box. I am getting the results on console but that is not showing item text (I think getting hidden behind bootsrap's modal).
Thanks in advance.

Can't show json in angular

body: Object
und: Array[1]
0: Object
format: "full_html"
safe_summary: ""
safe_value: "<p dir="rtl" style="text-align: justify;">اگر دوست دارید قدرت دویدنتان زیاد شود و بیشتر بدوید و آسیب های ناشی از دویدن را هم نداشه باشید توصیه های زیر را بخوانید تا موفقیت خوبی هنگام دویدن نصیبتان شود.<br /><strong>1- هر روز بدوید</strong><br />تداوم، کلید موفقیت در برنامه است. اگر هر روز بدوید، توانایی بدن برای سوزاندن چربی هم بیشتر می شود.<br /><br /><strong>2- لباس مناسب برای دویدن بپوشید</strong><br />بلوز،‌ شلوار و کفش ورزشی مناسب برای دویدن بپوشید. این کار هم بدن شما را در بهترین فرم و حالت نگه می دارد و هم انگیزه بخش بوده و یک وسیله تشویقی برای دویدن محسوب می شود.<br /><br /><strong>3- انعطاف پذیری خودتون را افزایش بدهید</strong><br />از تجهیزات ورزشی مناسب برای افزایش انعطاف پذیری بدن استفاده کنید تا در زمان دویدن، توانایی و ظرفیت بیشتری داشته باشید. مثلاً می توانید سه جلسه در هفته از بالش پیلاتس استفاده کنید. استفاده از این وسیله، احتمال جراحت هنگام دویدن را کمتر کرده و اثرات مفیدتری نسبت به حرکات کششی ایستا دارد<br /> <br /><strong>4- برای دویدن دلیل داشته باشید</strong><br />به یاد داشته باشید که شما از فرصت فوق العاده ای در زندگی بهرمند هستید که شاید خیلی از افراد دیگر، این فرصت رو نداشته باشند و به هر دلیلی نتوانند بدوند. این یک دلیل فوق العاده مهم و ارزشمند است. این فرصت را که به طور طبیعی در اختیار شما قرار داده شده است، هدر ندهید.<br /><br /><strong>5- هنگام دویدن لباس های خیلی گرم یا زیاد نپوشید</strong><br />همیشه طوری لباس بپوشید که انگار دمای محیط چند درجه گرم تر از میزان واقعی آن است. چون وقتی که شروع به دویدن می کنید،‌ بدن به طور خود به خود گرم می شود و اگر لباس زیادی پوشیده باشید،‌ احساس گرمای طاقت فرسایی خواهید کرد.<br />هرچه انعطاف بدن بیشتر باشد احتمال جراحت هنگام دویدن کمتر است<br /><br /><strong>6- با دونده های دیگر خودتان را مقایسه نکنید</strong><br />خودتان را با خودتان مقایسه کنید نه با بقیه دونده ها. مسلماً همیشه فرد یا افرادی وجود دارند که از شما سریع تر می دوند و ورزشکار تر به نظر می رسند. بر روی پیشرفت خودتان تمرکز کنید و افکار منفی و دلسرد کننده را از خودتان دور کنید.<br /><br /><strong>7- برای دویدن از سطوح شیب دار استفاده نکنید</strong><br />هیچ وقت در سراشیب تپه ها ندوید. نیروی بسیار شدید که با دویدن در سراشیب به زانو ها وارد می شود، برای زانوها مضر است.<br /><br /><strong>8- هر روز به خودتان فشار نیاورید</strong><br />برای تقویت بدن،‌ باید به آن فرصت بدهید تا به بازسازی خود بپردازد. پس نباید هر روز با شدت خیلی زیاد ورزش کنید. بعضی از روزهای هفته به ورزش با شدت کمتر بپردازید.<br /><br /><strong>9- به صورت گروهی بدوید</strong><br />دویدن حتی به صورت انفرادی هم لذتبخش است اما اگر فرد اجتماعی هستید و دوستانی دارید که به شما انگیزه می دهند، بهتر است که با هم به دویدن بپردازید.<br /><br /><strong>10- هنگام دویدن یک هدف مشخص تعیین کنید</strong><br />مثلاً با خودتان قرار بگذارید که یک ربع بدوید یا مثلاً چهار کیلومتر بدوید. سعی کنید که به هدفی که تعیین کرده اید،‌ برسید.</p>↵"
summary: ""
value: "<p dir="rtl" style="text-align: justify;">اگر دوست دارید قدرت دویدنتان زیاد شود و بیشتر بدوید و آسیب های ناشی از دویدن را هم نداشه باشید توصیه های زیر را بخوانید تا موفقیت خوبی هنگام دویدن نصیبتان شود.<br><strong>1- هر روز بدوید</strong><br>تداوم، کلید موفقیت در برنامه است. اگر هر روز بدوید، توانایی بدن برای سوزاندن چربی هم بیشتر می شود.<br><br><strong>2- لباس مناسب برای دویدن بپوشید</strong><br>بلوز،‌ شلوار و کفش ورزشی مناسب برای دویدن بپوشید. این کار هم بدن شما را در بهترین فرم و حالت نگه می دارد و هم انگیزه بخش بوده و یک وسیله تشویقی برای دویدن محسوب می شود.<br><br><strong>3- انعطاف پذیری خودتون را افزایش بدهید</strong><br>از تجهیزات ورزشی مناسب برای افزایش انعطاف پذیری بدن استفاده کنید تا در زمان دویدن، توانایی و ظرفیت بیشتری داشته باشید. مثلاً می توانید سه جلسه در هفته از بالش پیلاتس استفاده کنید. استفاده از این وسیله، احتمال جراحت هنگام دویدن را کمتر کرده و اثرات مفیدتری نسبت به حرکات کششی ایستا دارد<br> <br><strong>4- برای دویدن دلیل داشته باشید</strong><br>به یاد داشته باشید که شما از فرصت فوق العاده ای در زندگی بهرمند هستید که شاید خیلی از افراد دیگر، این فرصت رو نداشته باشند و به هر دلیلی نتوانند بدوند. این یک دلیل فوق العاده مهم و ارزشمند است. این فرصت را که به طور طبیعی در اختیار شما قرار داده شده است، هدر ندهید.<br><br><strong>5- هنگام دویدن لباس های خیلی گرم یا زیاد نپوشید</strong><br>همیشه طوری لباس بپوشید که انگار دمای محیط چند درجه گرم تر از میزان واقعی آن است. چون وقتی که شروع به دویدن می کنید،‌ بدن به طور خود به خود گرم می شود و اگر لباس زیادی پوشیده باشید،‌ احساس گرمای طاقت فرسایی خواهید کرد.<br>هرچه انعطاف بدن بیشتر باشد احتمال جراحت هنگام دویدن کمتر است<br><br><strong>6- با دونده های دیگر خودتان را مقایسه نکنید</strong><br>خودتان را با خودتان مقایسه کنید نه با بقیه دونده ها. مسلماً همیشه فرد یا افرادی وجود دارند که از شما سریع تر می دوند و ورزشکار تر به نظر می رسند. بر روی پیشرفت خودتان تمرکز کنید و افکار منفی و دلسرد کننده را از خودتان دور کنید.<br><br><strong>7- برای دویدن از سطوح شیب دار استفاده نکنید</strong><br>هیچ وقت در سراشیب تپه ها ندوید. نیروی بسیار شدید که با دویدن در سراشیب به زانو ها وارد می شود، برای زانوها مضر است.<br><br><strong>8- هر روز به خودتان فشار نیاورید</strong><br>برای تقویت بدن،‌ باید به آن فرصت بدهید تا به بازسازی خود بپردازد. پس نباید هر روز با شدت خیلی زیاد ورزش کنید. بعضی از روزهای هفته به ورزش با شدت کمتر بپردازید.<br><br><strong>9- به صورت گروهی بدوید</strong><br>دویدن حتی به صورت انفرادی هم لذتبخش است اما اگر فرد اجتماعی هستید و دوستانی دارید که به شما انگیزه می دهند، بهتر است که با هم به دویدن بپردازید.<br><br><strong>10- هنگام دویدن یک هدف مشخص تعیین کنید</strong><br>مثلاً با خودتان قرار بگذارید که یک ربع بدوید یا مثلاً چهار کیلومتر بدوید. سعی کنید که به هدفی که تعیین کرده اید،‌ برسید.</p>"
changed: "1440225054"
cid: "0"
comment: "2"
comment_count: "0"
created: "1440225054"
data: "b:0;"
field_external_link: Array[0]
field_image: Object
field_main_category_field: Object
field_show_slideshow: Object
title_original: "10 نکته برای بهتر دویدن"
This is my json from console that i copy here . This json is comming from Drupal that i want to show some data in ng-repeat .
when i add this to my html :
<div ng-repeat="data in innerData">
{{data.title_original}}
</div>
I'm assuming data is the variable holding the json. If that's true, I don't see any field title_original in it. Therefor, your code won't output anything.
Also, I see your json has some html in it. If you're sure the code is safe and can't inject unwanted tags (such as <script></script>), you should use the directive ng-bind-html to show that content and actually interpret it as HTML. This uses the sanitize module from angular.
See: https://docs.angularjs.org/api/ng/directive/ngBindHtml

ezxml xml parsing api

How to parse values if I have more than one tags, like in code above.
<formula1>
<team name="McLaren">
<driver>
<name>Abcd</name>
<points>112</points>
</driver>
<driver>
<name>Juan Pablo Montoya</name>
<points>60</points>
</driver>
</team>
</formula1>
<formula1>
<team name="McLaren">
<driver>
<name>Kimi Raikkonen</name>
<points>112</points>
</driver>
<driver>
<name>EFGH</name>
<points>60</points>
</driver>
</team>
</formula1>
I was able to print values between tags in first formula1 () with this code example:
ezxml_t f1 = ezxml_parse_file("formula1.xml");
printf("%s\n", ezxml_get(f1, "team", 0, "driver", 1, "name", -1)->txt);
ezxml_free(f1);
But don't know how to print values from second.
option 1. wrap
xml:
<root>
<formula1>
<team name="McLaren">
<driver>
<name>Abcd</name>
<points>112</points>
</driver>
<driver>
<name>Juan Pablo Montoya</name>
<points>60</points>
</driver>
</team>
</formula1>
<formula1>
<team name="McLaren">
<driver>
<name>Kimi Raikkonen</name>
<points>112</points>
</driver>
<driver>
<name>EFGH</name>
<points>60</points>
</driver>
</team>
</formula1>
</root>
code:
printf("%s\n", ezxml_get(f1, "formula1", 0, "team", 0, "driver", 1, "name", -1)->txt);
printf("%s\n", ezxml_get(f1, "formula1", 1, "team", 0, "driver", 0, "name", -1)->txt);
option 2. unify
xml:
<formula1>
<team name="McLaren">
<driver>
<name>Abcd</name>
<points>112</points>
</driver>
<driver>
<name>Juan Pablo Montoya</name>
<points>60</points>
</driver>
</team>
<team name="McLaren">
<driver>
<name>Kimi Raikkonen</name>
<points>112</points>
</driver>
<driver>
<name>EFGH</name>
<points>60</points>
</driver>
</team>
</formula1>
code:
printf("%s\n", ezxml_get(f1, "team", 0, "driver", 1, "name", -1)->txt);
printf("%s\n", ezxml_get(f1, "team", 1, "driver", 0, "name", -1)->txt);

Snake Game: Why "(Sometimes, lower than 10%)" the snacks (cookies) are created on the snake body?

Here is my code snippet.
Filled_Func () is to sort my "non-snake-body" position in increase order. In other words, I use Filled[] to hold unfilled squares. :-)
Create_Cookie () is to choose the cookie position, get random value by time(), and draw cookie by calling Draw_Square ().
void Filled_Func (void)
{
int Cnt_X, Cnt_Y, Cnt_2, Cnt_3 = 0, Flag = 1;
for (Cnt_X = 0; Cnt_X < 25; Cnt_X++)
{
for (Cnt_Y = 0, Flag = 1; Cnt_Y < 25; Cnt_Y++)
{
for (Cnt_2 = 0 ; Cnt_2 < Move.Snake_Length; Cnt_2++)
{
if (Move.Position[Cnt_2].X == Cnt_X && Move.Position[Cnt_2].Y == Cnt_Y)
{
Flag = 0;
break;
}
}
if (Flag == 1)
{
Filled[Cnt_3].X = Cnt_X;
Filled[Cnt_3].Y = Cnt_Y;
Cnt_3++;
}
}
}
}
void Create_Cookie (HDC DeviceContext)
{
Filled_Func ();
int Rand = clock()%(625-Move.Snake_Length);
Cookie.X = Filled[Rand].X;
Cookie.Y = Filled[Rand].Y;
Draw_Square (Cookie.X, Cookie.Y, UP, RGB( 0 ,255, 0 ), -1, -1, UP, RGB(255,255,255), 0, DeviceContext);
}
My repository on Github.
My full C code in plain text (v1.00).
My full C code in plain text (v1.01). (I've changed Filled[] into Unfilled[])
Download executable and code.
Any help, suggestion, and advice will be very very appreciated. :-)
Added on NOV 30 AM 11:00 (GMT AM 3:00)
I trace the snake coordinate with outputing a log file:
Format: the snake coordinate --> the cookie coordinate
(12,12) (12,13) --> [17,06]
(17,06) (17,07) (17,08) --> [23,18]
(23,15) (23,16) (23,17) (23,18) --> [18,00]
(14,00) (15,00) (16,00) (17,00) (18,00) --> [22,14]
(17,14) (18,14) (19,14) (20,14) (21,14) (22,14) --> [04,06]
(04,06) (04,07) (05,07) (06,07) (07,07) (08,07) (09,07) --> [19,11]
(19,11) (20,11) (21,11) (22,11) (23,10) (23,11) (24,10) (24,11) --> [20,04]
(18,10) (19,10) (20,04) (20,05) (20,06) (20,07) (20,08) (20,09) (20,10) --> [16,18]
(09,19) (09,20) (10,19) (11,19) (12,19) (13,19) (14,19) (15,19) (16,18) (16,19) --> [19,07]
(19,07) (19,08) (19,09) (19,10) (19,11) (19,12) (20,08) (20,09) (20,10) (20,11) (20,12) --> [21,18]
(20,13) (20,14) (20,15) (20,16) (20,17) (20,18) (21,13) (21,14) (21,15) (21,16) (21,17) (21,18) --> [24,06]
(22,06) (22,07) (22,08) (22,09) (22,10) (22,11) (22,12) (22,13) (22,14) (22,15) (22,16) (23,06) (24,06) --> [18,15]
(17,04) (17,05) (17,06) (17,07) (17,08) (17,09) (17,10) (17,11) (17,12) (17,13) (17,14) (17,15) (18,04) (18,15) --> [00,18]
(00,15) (00,16) (00,17) (00,18) (17,12) (17,13) (17,14) (17,15) (18,15) (19,15) (20,15) (21,15) (22,15) (23,15) (24,15) --> [13,06]
(04,00) (05,00) (06,00) (07,00) (08,00) (09,00) (10,00) (11,00) (12,00) (13,00) (13,01) (13,02) (13,03) (13,04) (13,05) (13,06) --> [15,21]
(13,07) (13,08) (13,09) (13,10) (13,11) (13,12) (13,13) (13,14) (13,15) (13,16) (13,17) (13,18) (13,19) (13,20) (13,21) (14,21) (15,21) --> [18,13]
(13,21) (14,21) (15,21) (16,21) (17,21) (18,13) (18,21) (19,13) (19,21) (20,13) (20,14) (20,15) (20,16) (20,17) (20,18) (20,19) (20,20) (20,21) --> [24,18]
(12,16) (12,17) (12,18) (12,19) (12,20) (13,20) (14,20) (15,20) (16,20) (17,20) (18,20) (19,20) (20,20) (21,20) (22,20) (23,20) (24,18) (24,19) (24,20) --> [21,17]
(03,18) (04,18) (05,18) (06,18) (07,18) (08,18) (09,18) (10,18) (11,18) (12,18) (13,18) (14,18) (15,17) (15,18) (16,17) (17,17) (18,17) (19,17) (20,17) (21,17) --> [04,02]
(04,02) (05,02) (06,02) (07,02) (08,02) (09,02) (10,02) (11,02) (12,02) (13,02) (14,02) (15,02) (15,03) (15,04) (15,05) (15,06) (15,07) (15,08) (15,09) (15,10) (15,11) --> [19,01]
(17,01) (17,02) (17,03) (17,04) (17,05) (17,06) (17,07) (17,08) (17,09) (17,10) (17,11) (17,12) (17,13) (17,14) (17,15) (17,16) (17,17) (17,18) (17,19) (17,20) (18,01) (19,01) --> [08,17]
(02,01) (03,01) (04,01) (05,01) (06,01) (06,02) (06,03) (06,04) (06,05) (06,06) (06,07) (06,08) (06,09) (06,10) (06,11) (06,12) (06,13) (06,14) (06,15) (06,16) (06,17) (07,17) (08,17) --> [23,14]
(01,15) (02,15) (03,15) (04,15) (05,15) (06,15) (07,15) (08,15) (09,15) (10,15) (11,15) (12,15) (13,15) (14,15) (15,15) (16,15) (17,15) (18,15) (19,15) (20,15) (21,15) (22,15) (23,14) (23,15) --> [24,09]
(01,08) (02,08) (03,08) (04,08) (05,08) (06,08) (07,08) (08,08) (09,08) (10,08) (11,08) (12,08) (13,08) (14,08) (15,08) (16,08) (17,08) (18,08) (19,08) (20,08) (21,08) (22,08) (23,08) (24,08) (24,09) --> [24,10]
(01,08) (02,08) (03,08) (04,08) (05,08) (06,08) (07,08) (08,08) (09,08) (10,08) (11,08) (12,08) (13,08) (14,08) (15,08) (16,08) (17,08) (18,08) (19,08) (20,08) (21,08) (22,08) (23,08) (24,08) (24,09) (24,10) --> [00,01]
(00,01) (00,02) (01,02) (02,02) (03,02) (04,02) (05,02) (06,02) (07,02) (08,02) (09,02) (10,02) (11,02) (12,02) (13,02) (14,02) (15,02) (16,02) (17,02) (18,02) (19,02) (20,02) (21,02) (22,02) (23,02) (24,01) (24,02) --> [08,03]
(00,04) (00,05) (00,06) (00,07) (00,08) (00,09) (00,10) (01,04) (02,04) (03,04) (04,04) (05,04) (06,04) (07,04) (08,00) (08,01) (08,02) (08,03) (08,04) (08,23) (08,24) (09,00) (09,01) (09,02) (09,03) (09,04) (09,23) (09,24) --> [19,04]
(08,00) (08,01) (08,02) (08,03) (08,04) (08,05) (08,06) (08,07) (08,08) (08,09) (08,23) (08,24) (09,09) (09,23) (10,09) (11,09) (12,09) (13,09) (14,09) (15,09) (16,09) (17,09) (18,09) (19,04) (19,05) (19,06) (19,07) (19,08) (19,09) --> [24,09]
(13,09) (14,09) (15,09) (16,09) (17,09) (18,09) (19,00) (19,01) (19,02) (19,03) (19,04) (19,05) (19,06) (19,07) (19,08) (19,09) (20,00) (21,00) (22,00) (23,00) (24,00) (24,01) (24,02) (24,03) (24,04) (24,05) (24,06) (24,07) (24,08) (24,09) --> [16,01]
(14,01) (14,02) (14,03) (14,04) (14,05) (14,06) (14,07) (14,08) (14,09) (14,10) (14,11) (14,12) (14,13) (14,14) (15,01) (15,14) (16,01) (16,14) (17,14) (18,14) (19,14) (20,14) (21,14) (22,14) (23,14) (24,09) (24,10) (24,11) (24,12) (24,13) (24,14) --> [02,12]
(02,02) (02,03) (02,04) (02,05) (02,06) (02,07) (02,08) (02,09) (02,10) (02,11) (02,12) (03,02) (03,11) (03,12) (04,11) (04,12) (05,11) (05,12) (06,11) (06,12) (07,11) (07,12) (08,11) (08,12) (09,11) (09,12) (10,11) (10,12) (11,11) (11,12) (12,11) (12,12) --> [08,04]
(08,00) (08,01) (08,02) (08,03) (08,04) (08,23) (08,24) (09,23) (10,23) (11,23) (12,23) (13,23) (14,00) (14,01) (14,02) (14,03) (14,04) (14,05) (14,06) (14,07) (14,08) (14,09) (14,10) (14,11) (14,12) (14,23) (14,24) (15,12) (16,12) (17,12) (18,12) (19,12) (20,12) --> [24,17]
(08,00) (08,01) (08,02) (08,03) (08,04) (08,05) (08,06) (08,07) (08,08) (08,09) (08,10) (08,11) (08,12) (08,13) (08,14) (09,14) (10,14) (11,14) (12,14) (13,14) (14,14) (15,14) (16,14) (17,14) (18,14) (19,14) (20,14) (21,14) (22,14) (23,14) (24,14) (24,15) (24,16) (24,17) --> [12,05]
(10,04) (10,05) (10,06) (10,07) (10,08) (10,09) (11,04) (11,09) (12,04) (12,05) (12,09) (13,04) (13,05) (13,09) (14,04) (14,05) (14,09) (15,04) (15,05) (15,09) (16,04) (16,05) (16,09) (17,04) (17,05) (17,09) (18,09) (19,09) (19,10) (19,11) (19,12) (19,13) (19,14) (19,15) (19,16) --> [03,04]
(02,00) (02,01) (02,02) (02,03) (02,04) (02,05) (02,23) (02,24) (03,04) (03,05) (03,23) (04,00) (04,01) (04,02) (04,03) (04,04) (04,05) (04,23) (04,24) (05,04) (05,05) (06,04) (06,05) (07,04) (07,05) (08,04) (08,05) (09,05) (10,05) (11,05) --> [22,16]
(00,04) (01,04) (02,04) (03,04) (04,04) (05,04) (06,04) (06,05) (07,04) (07,05) (08,04) (08,05) (17,04) (17,05) (17,06) (17,07) (17,08) (17,09) (17,10) (17,11) (17,12) (17,13) (17,14) (17,15) (17,16) (18,04) (18,16) (19,04) (19,16) (20,04) (20,16) (21,04) (21,16) (22,04) (22,16) (23,04) (24,04) --> [24,17]
(04,16) (05,16) (06,16) (07,16) (08,16) (09,16) (10,16) (11,16) (12,16) (13,16) (14,16) (15,16) (16,16) (17,16) (18,16) (19,16) (20,16) (21,16) (22,16) (23,00) (23,16) (23,17) (23,18) (23,19) (23,20) (23,21) (23,22) (23,23) (23,24) (24,00) (24,17) (24,18) (24,19) (24,20) (24,21) (24,22) (24,23) (24,24) --> [18,09]
(05,09) (05,10) (06,09) (06,10) (07,09) (07,10) (08,09) (08,10) (09,09) (09,10) (10,09) (10,10) (11,09) (11,10) (12,09) (12,10) (13,09) (13,10) (14,09) (14,10) (15,09) (15,10) (16,09) (16,10) (17,09) (17,10) (18,09) (18,10) (19,10) (20,10) (20,11) (21,10) (21,11) (22,10) (22,11) (23,10) (23,11) (24,10) (24,11) --> [01,11]
(01,11) (01,12) (01,13) (01,14) (01,15) (01,16) (01,17) (01,18) (01,19) (01,20) (02,08) (02,09) (02,10) (02,11) (02,12) (02,13) (02,14) (02,15) (02,16) (02,17) (02,18) (02,19) (02,20) (03,08) (04,08) (05,08) (06,08) (07,08) (08,08) (09,08) (10,08) (11,08) (12,08) (13,08) (14,08) (15,08) (16,08) (17,08) (18,08) (19,08) --> [14,01]
(01,09) (01,10) (02,09) (03,09) (04,09) (05,09) (06,09) (07,09) (08,09) (09,09) (10,09) (11,09) (12,09) (13,00) (13,01) (13,02) (13,03) (13,04) (13,05) (13,06) (13,07) (13,08) (13,09) (14,00) (14,01) (15,00) (15,01) (16,00) (16,01) (17,00) (17,01) (18,00) (18,01) (19,00) (19,01) (20,00) (20,01) (21,00) (21,01) (22,00) (22,01) --> [24,01]
(07,01) (07,02) (07,03) (08,01) (08,03) (09,01) (09,03) (10,01) (10,03) (11,01) (11,03) (12,01) (12,03) (13,01) (13,03) (14,01) (14,03) (15,01) (15,03) (16,01) (16,03) (17,01) (17,03) (18,00) (18,01) (18,03) (19,00) (19,01) (19,03) (20,00) (20,01) (20,03) (21,00) (21,01) (21,03) (22,00) (22,01) (22,03) (23,03) (24,01) (24,02) (24,03) --> [23,18]
(09,03) (10,03) (11,03) (12,03) (13,03) (14,03) (15,03) (15,20) (15,21) (16,03) (16,20) (16,21) (17,03) (17,20) (17,21) (18,03) (18,20) (18,21) (19,03) (19,20) (19,21) (20,03) (20,20) (20,21) (21,03) (21,20) (21,21) (22,03) (22,20) (22,21) (23,03) (23,18) (23,19) (23,20) (23,21) (24,00) (24,01) (24,02) (24,03) (24,21) (24,22) (24,23) (24,24) --> [05,18]
(05,12) (05,13) (05,14) (05,15) (05,16) (05,17) (05,18) (06,12) (07,12) (08,12) (09,12) (10,12) (11,12) (12,12) (13,12) (14,12) (15,12) (15,20) (15,21) (16,12) (16,20) (16,21) (17,12) (17,20) (17,21) (18,12) (18,20) (19,12) (19,20) (20,12) (20,20) (21,12) (21,20) (22,12) (22,20) (23,12) (23,13) (23,14) (23,15) (23,16) (23,17) (23,18) (23,19) (23,20) --> [23,06]
(00,05) (00,06) (01,05) (01,06) (10,19) (11,19) (12,19) (13,19) (14,19) (15,19) (16,19) (17,19) (18,10) (18,11) (18,12) (18,13) (18,14) (18,15) (18,16) (18,17) (18,18) (18,19) (19,10) (20,04) (20,05) (20,10) (21,04) (21,05) (21,10) (22,04) (22,05) (22,10) (23,04) (23,05) (23,06) (23,10) (24,04) (24,05) (24,06) (24,07) (24,08) (24,09) (24,10) --> [06,07]
(00,06) (01,06) (06,07) (06,08) (06,09) (06,10) (06,11) (06,12) (06,13) (06,14) (06,15) (06,16) (06,17) (06,18) (06,19) (07,06) (07,07) (07,08) (07,09) (07,10) (07,11) (07,12) (07,13) (07,14) (07,15) (07,16) (07,17) (07,18) (07,19) (08,06) (09,06) (10,06) (11,06) (12,06) (13,06) (14,06) (15,06) (16,06) (17,06) (18,06) (19,06) (20,06) (21,06) (22,06) (23,06) (24,06) --> [14,07]
(06,05) (06,06) (06,07) (06,08) (06,09) (06,10) (06,11) (06,12) (06,13) (06,14) (06,15) (06,16) (06,17) (06,18) (06,19) (07,05) (07,06) (07,07) (07,08) (07,09) (07,10) (07,11) (07,12) (07,13) (07,14) (07,15) (07,16) (07,17) (07,18) (07,19) (08,05) (08,06) (09,05) (09,06) (10,05) (10,06) (11,05) (11,06) (12,05) (12,06) (13,05) (13,06) (14,05) (14,06) (14,07) (15,06) --> [18,20]
(06,05) (06,06) (06,07) (07,05) (08,05) (09,05) (10,05) (11,05) (12,05) (13,05) (14,05) (14,06) (14,07) (14,08) (14,09) (14,10) (14,11) (14,12) (14,13) (14,14) (14,15) (14,16) (14,17) (14,18) (14,19) (15,19) (16,19) (17,19) (18,19) (18,20) (18,21) (18,22) (18,23) (19,19) (19,23) (20,19) (20,23) (21,19) (21,23) (22,19) (22,23) (23,19) (23,23) (24,19) (24,20) (24,21) (24,22) (24,23) --> [23,20]
(14,17) (14,18) (14,19) (15,19) (16,19) (17,19) (18,14) (18,15) (18,16) (18,17) (18,18) (18,19) (18,20) (18,21) (18,22) (18,23) (19,14) (19,19) (19,23) (20,14) (20,19) (20,23) (21,14) (21,19) (21,23) (22,14) (22,19) (22,23) (23,14) (23,19) (23,20) (23,21) (23,22) (23,23) (24,14) (24,15) (24,16) (24,17) (24,18) (24,19) (24,20) (24,21) (24,22) (24,23) --> [08,24]
(07,12) (07,13) (07,14) (07,15) (07,16) (07,17) (07,18) (07,19) (07,20) (07,21) (07,22) (07,23) (07,24) (08,12) (08,24) (09,12) (10,12) (11,12) (12,12) (13,12) (14,12) (15,12) (16,12) (17,12) (18,12) (19,12) (20,12) (21,12) (22,12) (23,12) (23,13) (23,14) (23,15) (23,16) (23,17) (23,18) (23,19) (23,20) (23,21) (23,22) (24,14) (24,15) (24,16) (24,17) (24,18) (24,19) (24,20) (24,21) (24,22) --> [01,03]
(01,03) (01,04) (02,04) (03,04) (04,04) (05,04) (06,04) (07,04) (07,12) (07,13) (07,14) (07,15) (07,16) (07,17) (07,18) (07,19) (07,20) (07,21) (07,22) (07,23) (07,24) (08,04) (08,12) (08,24) (09,04) (09,12) (09,24) (10,04) (10,12) (10,24) (11,04) (11,12) (11,24) (12,04) (12,24) (13,04) (13,24) (14,04) (14,24) (15,04) (15,24) (16,04) (16,24) (17,04) (17,24) (18,00) (18,01) (18,02) (18,03) (18,04) (18,24) --> [15,03]
(01,00) (01,01) (01,02) (01,03) (01,04) (01,11) (01,12) (01,13) (01,14) (01,15) (01,16) (01,17) (01,18) (01,19) (01,20) (01,21) (01,22) (01,23) (01,24) (02,04) (02,11) (03,04) (03,11) (04,04) (04,11) (05,04) (05,11) (06,04) (06,11) (07,04) (07,11) (08,04) (08,11) (09,04) (09,11) (10,04) (10,11) (11,04) (11,11) (12,04) (12,11) (13,11) (14,11) (15,03) (15,04) (15,05) (15,06) (15,07) (15,08) (15,09) (15,10) (15,11) --> [13,10]
(01,11) (01,12) (01,13) (01,14) (01,15) (01,16) (01,17) (01,18) (01,19) (01,20) (01,21) (02,11) (03,11) (04,11) (05,11) (06,11) (07,11) (08,11) (09,11) (10,11) (11,11) (12,11) (13,10) (13,11) (14,10) (14,11) (15,00) (15,01) (15,02) (15,03) (15,04) (15,05) (15,06) (15,07) (15,08) (15,09) (15,10) (15,11) (15,12) (15,13) (15,14) (15,15) (15,16) (15,17) (15,18) (15,19) (15,20) (15,21) (15,22) (15,23) (15,24) --> [17,09]
(06,09) (06,10) (07,09) (07,10) (08,09) (08,10) (09,09) (09,10) (09,11) (10,09) (10,10) (10,11) (11,09) (11,10) (11,11) (12,09) (12,10) (12,11) (13,09) (13,10) (13,11) (14,09) (14,10) (14,11) (15,00) (15,01) (15,02) (15,03) (15,04) (15,05) (15,06) (15,07) (15,08) (15,09) (15,10) (15,11) (15,12) (15,13) (15,14) (15,15) (15,16) (15,17) (15,18) (15,19) (15,20) (15,21) (15,22) (15,23) (15,24) (16,09) (17,09) --> [18,19]
(12,13) (12,14) (12,15) (12,16) (12,17) (12,18) (13,13) (13,18) (14,10) (14,11) (14,12) (14,13) (14,14) (14,15) (14,16) (14,17) (14,18) (14,19) (14,20) (15,10) (15,13) (15,18) (15,20) (16,10) (16,13) (16,18) (16,20) (17,10) (17,13) (17,18) (17,20) (18,10) (18,13) (18,18) (18,19) (18,20) (19,10) (19,13) (19,14) (19,15) (19,16) (19,17) (19,18) (19,19) (19,20) (20,09) (20,10) (21,09) (21,10) (22,09) (22,10) --> [04,09]
(04,09) (04,10) (04,11) (04,12) (04,13) (04,14) (04,15) (04,16) (04,17) (04,18) (04,19) (05,19) (06,19) (07,19) (08,19) (09,19) (10,19) (11,19) (12,13) (12,14) (12,15) (12,16) (12,17) (12,18) (12,19) (13,13) (13,18) (13,19) (14,13) (14,18) (14,19) (15,13) (15,18) (15,19) (16,13) (16,18) (16,19) (16,20) (17,13) (17,18) (17,19) (17,20) (18,13) (18,18) (18,19) (18,20) (19,13) (19,14) (19,15) (19,16) (19,17) (19,18) (19,19) (19,20) --> [01,13]
(01,11) (01,12) (01,13) (02,11) (03,11) (04,09) (04,10) (04,11) (04,12) (04,13) (04,14) (04,15) (04,16) (04,17) (04,18) (04,19) (05,09) (05,11) (05,19) (06,09) (06,11) (06,19) (07,09) (07,11) (07,19) (08,09) (08,11) (08,19) (09,09) (09,11) (09,19) (10,09) (10,10) (10,11) (10,19) (11,19) (12,14) (12,15) (12,16) (12,17) (12,18) (12,19) (13,18) (13,19) (14,18) (14,19) (15,18) (15,19) (16,18) (16,19) (17,18) (17,19) (18,18) (18,19) (19,18) (19,19) --> [11,06]
(01,11) (01,12) (01,13) (01,14) (01,15) (01,16) (01,17) (01,18) (01,19) (02,11) (02,19) (03,11) (03,19) (04,11) (04,19) (05,11) (05,19) (06,11) (06,19) (07,11) (07,19) (08,11) (08,19) (09,09) (09,11) (09,19) (10,05) (10,06) (10,07) (10,08) (10,09) (10,10) (10,11) (10,12) (10,13) (10,14) (10,15) (10,16) (10,17) (10,18) (10,19) (11,05) (11,06) (12,05) (12,06) (13,05) (13,06) (14,05) (14,06) (15,05) (15,06) (16,05) (16,06) (17,05) (17,06) --> [24,11]
(06,19) (07,06) (07,07) (07,19) (08,06) (08,07) (08,19) (09,06) (09,07) (09,19) (10,05) (10,06) (10,07) (10,08) (10,09) (10,10) (10,11) (10,12) (10,13) (10,14) (10,15) (10,16) (10,17) (10,18) (10,19) (11,05) (11,06) (11,07) (12,05) (12,06) (12,07) (13,05) (13,06) (13,07) (14,05) (14,06) (14,07) (15,05) (15,06) (15,07) (16,05) (16,06) (16,07) (17,05) (17,06) (17,07) (18,07) (19,07) (20,07) (21,07) (22,07) (23,07) (24,07) (24,08) (24,09) (24,10) (24,11) --> [04,01]
(00,00) (00,01) (01,00) (01,01) (02,00) (02,01) (03,00) (03,01) (04,00) (04,01) (05,00) (05,01) (05,02) (05,03) (05,04) (05,05) (05,06) (05,07) (05,08) (05,09) (05,10) (05,11) (05,12) (05,13) (05,14) (05,15) (05,16) (05,17) (05,18) (05,19) (05,20) (05,21) (05,22) (05,23) (05,24) (06,05) (07,05) (08,05) (09,05) (10,05) (11,05) (12,05) (13,05) (14,05) (15,05) (16,05) (16,06) (16,07) (16,08) (16,09) (23,00) (23,01) (24,00) (24,01) --> [24,12]
(00,00) (00,01) (00,11) (00,13) (01,00) (01,01) (01,11) (01,13) (02,00) (02,01) (02,11) (02,13) (03,01) (03,11) (03,13) (04,01) (04,11) (04,13) (05,01) (05,11) (05,13) (06,01) (06,11) (06,13) (07,01) (07,11) (07,12) (07,13) (08,01) (09,01) (10,01) (11,01) (12,01) (13,01) (14,01) (15,01) (16,01) (17,01) (18,01) (19,01) (20,01) (21,01) (22,01) ****(23,00)**** (23,01) (23,02) (23,03) (23,04) (23,05) (23,06) (23,07) (23,08) (23,09) (23,10) (23,11) (24,00) (24,01) (24,11) (24,12) (24,13) --> [23,00]
See the last line, where bug happens: The snack (cookie) was created at (23,00), but (23,00) was already occupied by the snake !!!
Why? Could anyone help me? Any help, suggestion, and advice will be very very appreciated. :-)
Without actually reading the code in details: you seem to fill a Filled[index] tab with ONLY unfilled coordinates. Then you choose one of them at random.
In that case, I expect to see, at the place where you test if a coordinate is occupied by the snake, some longer instructions than just having "Flag=0". You need to make sure you "shift" remaining Filled[index] so that only unfilled coordinates remains in that array! (think : linked-lists, and deletion of one as it now becomes "filled" by the snake)
#Olivier Dulac
I've updated my code on Github ( Plain Text ).
It works fine now. :-)
Solution
void Unfilled_Func (void)
{
int Cnt_X, Cnt_Y, Cnt_2, Cnt_3 = 0, Flag = 1;
for (Cnt_X = 0; Cnt_X < 25; Cnt_X++)
{
for (Cnt_Y = 0; Cnt_Y < 25; Cnt_Y++)
{
Flag = 1;
for (Cnt_2 = 0 ; Cnt_2 < Move.Snake_Length; Cnt_2++)
{
if (Move.Position[Cnt_2].X == Cnt_X && Move.Position[Cnt_2].Y == Cnt_Y)
{
Flag = 0;
break;
}
}
if (Flag == 1)
{
Unfilled[Cnt_3].X = Cnt_X;
Unfilled[Cnt_3].Y = Cnt_Y;
Cnt_3++;
}
}
}
Unfilled_Length = Cnt_3;
}
void Create_Cookie (HDC DeviceContext)
{
Unfilled_Func ();
int Rand = clock()%Unfilled_Length;
Cookie.X = Unfilled[Rand].X;
Cookie.Y = Unfilled[Rand].Y;
Draw_Square (Cookie.X, Cookie.Y, UP, RGB( 0 ,255, 0 ), -1, -1, UP, RGB(255,255,255), 0, DeviceContext);
}

Resources